3

Can someone help me to figure out why this code does not work?

services/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)
      }
    })
  })
}

sagas/auth.js

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

All functions seems to work, but I don't see any HTTP requests in Charles proxy; I put some console.log into cognitoUser.authenticateUser() function - it fires, but nothing happens. No errors in console, nothing. What could be wrong?

Thanks a lot.

Seva
  • 665
  • 1
  • 7
  • 17
  • I also have the same issue. The `cognitoUser.authenticateUser()` fires, but nothing happens.. Were you able to fix the problem? – IceCode Feb 26 '20 at 15:41
  • I've finally managed to fix that, but to be honest, I can't remember, how :( – Seva Feb 27 '20 at 13:42
  • No worries :) I used the new `aws-amplify` library instead of `amazon-cognito-identity-js` and it works great. – IceCode Feb 27 '20 at 14:41

0 Answers0