Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t使用AWS Cognito进行身份验证_Javascript_Reactjs_Amazon Web Services_React Native_Amazon Cognito - Fatal编程技术网

Javascript Can';t使用AWS Cognito进行身份验证

Javascript 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:

有人能帮我找出为什么这个代码不起作用吗

服务/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,
}
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
,效果很好。