S
S
Seva2018-02-05 21:08:38
JavaScript
Seva, 2018-02-05 21:08:38

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,
}

Service
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)
      }
    })
  })
}

Everything seems to work, the cognitoUser.authenticateUser function is called - but no errors in the console, just nothing happens.
What am I missing? Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question