Answer the question
In order to leave comments, you need to log in
Why can't I authenticate with AWS Cognito?
Hello,
I can't authenticate with Cognito.
Saga
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,
}
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)
}
})
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question