Javascript Can';t使用AWS Cognito进行身份验证
有人能帮我找出为什么这个代码不起作用吗 服务/auth.jsJavascript Can';t使用AWS Cognito进行身份验证,javascript,reactjs,amazon-web-services,react-native,amazon-cognito,Javascript,Reactjs,Amazon Web Services,React Native,Amazon Cognito,有人能帮我找出为什么这个代码不起作用吗 服务/auth.js import { CognitoUserPool, CognitoUserAttribute, CognitoUser, AuthenticationDetails } from 'react-native-aws-cognito-js'; const COGNITO_POOL = new CognitoUserPool({ region: 'us-west-1', IdentityPoolId:
import {
CognitoUserPool,
CognitoUserAttribute,
CognitoUser,
AuthenticationDetails
} from 'react-native-aws-cognito-js';
const COGNITO_POOL = new CognitoUserPool({
region: 'us-west-1',
IdentityPoolId: '****',
UserPoolId: '****',
ClientId: '****',
})
export const signIn = (data) => {
const authenticationDetails = new AuthenticationDetails({
Username: data.login,
Password: data.password
});
const cognitoUser = new CognitoUser({
Username: data.login,
Pool: COGNITO_POOL
});
return new Promise( (resolve, reject) => {
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: (result) => {
console.log(result);
resolve('access token + ' + result.getAccessToken().getJwtToken());
},
onFailure: (err) => {
console.log('onFailure', err)
},
mfaRequired: (codeDeliveryDetails) => {
console.log('mfaRequired', codeDeliveryDetails)
}
})
})
}
import {
LOGIN_REQUEST,
SET_AUTH,
} from 'actions/types';
import { take, call, put, race } from 'redux-saga/effects';
import * as AuthService from 'services/auth';
const signIn = function* signIn() {
while (true) {
const request = yield take(LOGIN_REQUEST);
try {
response = yield call(AuthService.signIn, { login: request.data.login, password: request.data.password });
} catch (error) {
return false;
}
yield put({ type: SET_AUTH, response });
}
}
export {
signIn,
}
sagas/auth.js
import {
CognitoUserPool,
CognitoUserAttribute,
CognitoUser,
AuthenticationDetails
} from 'react-native-aws-cognito-js';
const COGNITO_POOL = new CognitoUserPool({
region: 'us-west-1',
IdentityPoolId: '****',
UserPoolId: '****',
ClientId: '****',
})
export const signIn = (data) => {
const authenticationDetails = new AuthenticationDetails({
Username: data.login,
Password: data.password
});
const cognitoUser = new CognitoUser({
Username: data.login,
Pool: COGNITO_POOL
});
return new Promise( (resolve, reject) => {
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: (result) => {
console.log(result);
resolve('access token + ' + result.getAccessToken().getJwtToken());
},
onFailure: (err) => {
console.log('onFailure', err)
},
mfaRequired: (codeDeliveryDetails) => {
console.log('mfaRequired', codeDeliveryDetails)
}
})
})
}
import {
LOGIN_REQUEST,
SET_AUTH,
} from 'actions/types';
import { take, call, put, race } from 'redux-saga/effects';
import * as AuthService from 'services/auth';
const signIn = function* signIn() {
while (true) {
const request = yield take(LOGIN_REQUEST);
try {
response = yield call(AuthService.signIn, { login: request.data.login, password: request.data.password });
} catch (error) {
return false;
}
yield put({ type: SET_AUTH, response });
}
}
export {
signIn,
}
所有的函数似乎都能工作,但我在Charles proxy中没有看到任何HTTP请求;我将一些console.log
放入cognitoUser.authenticateUser()
函数中-它启动,但什么也没发生。控制台中没有错误,什么都没有。有什么不对劲吗
非常感谢。我也有同样的问题。
cognitoUser.authenticateUser()
启动,但什么也没发生。。你能解决这个问题吗?我终于解决了,但说实话,我不记得是怎么解决的:(不用担心:)我用了新的aws amplify
库而不是amazon cognito identity js
,效果很好。