@Zewkin
Я у мамы фронтэндер

Почему не получается аутентифицироваться в AWS Cognito?

Привет,

не получается аутентифицироваться в Когнито.

Сага

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


Вроде все работает, функция cognitoUser.authenticateUser вызывается - но никаких ошибок в консоли, просто ничего не происходит.

Что я упускаю? Спасибо.
  • Вопрос задан
  • 39 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы