React Native AWS Amplify AuthError:Amplify 尚未正确配置

Mad*_*dhu 5 javascript ios amazon-cognito react-native aws-amplify

我在我的 React Native 项目中使用 AWS Amplify 库并手动配置登录。我可以使用 React Native 项目登录 Android 应用程序,但是当我在 ios 中运行相同的 React Native 代码时,我得到了以下错误。我正在从 React Native 中的 .env 文件中获取放大配置参数数据。

我已按照以下步骤进行 iOS pod 安装来设置 Amplify 库 https://docs.amplify.aws/lib/auth/start/q/platform/js#configure-your-application

我已经在 iOS 中安装了与https://www.npmjs.com/package/react-native-config和 amplify 库相关的所有 pod 。

// import Amplify, { Auth } from 'aws-amplify';
   import Amplify from '@aws-amplify/core';
   import Auth from '@aws-amplify/auth';

  /** Configration of Cognito Auth Process for mobile client */
    Amplify.configure({
      Auth: {

  // REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
  identityPoolId: Config.REACT_APP_AWS_COGNITO_IDENTITY_POOL_ID,

  // REQUIRED - Amazon Cognito Region
  region:  Config.REACT_APP_AWS_COGNITO_REGION,

  // OPTIONAL - Amazon Cognito User Pool ID
  userPoolId: Config.REACT_APP_AWS_COGNITO_USER_POOL_ID,

  // OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
  userPoolWebClientId: Config.REACT_APP_AWS_COGNITO_USER_POOL_WEB_CLIENT_ID,

  // OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
  mandatorySignIn: false,

  // OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
  authenticationFlowType: 'USER_PASSWORD_AUTH',

   // OPTIONAL - Hosted UI configuration
  oauth: {
      domain: Config.REACT_APP_AWS_COGNITO_OAUTH_DOMAIN,
      scope: ['openid', 'aws.cognito.signin.user.admin'],
      redirectSignIn: Config.REACT_APP_AWS_COGNITO_OAUTH_REDIRECT_SIGNIN,
      redirectSignOut: Config.REACT_APP_AWS_COGNITO_OAUTH_REDIRECT_SIGNOUT,
      responseType: Config.REACT_APP_AWS_COGNITO_OAUTH_RESPONSE_TYPE, // or 'token', note 
      that REFRESH token will only be generated when the responseType is code
     }
     }.   
   });

   // You can get the current config object
    const currentConfig = Auth.configure();

  //Usage
   Auth.signIn(username, password).then(
    (result) => {
      console.log(result);
      if(result instanceof CognitoUser){
        console.log(result.getSignInUserSession()?.getAccessToken().getJwtToken());
        console.log(result.getSignInUserSession()?.getIdToken());
        console.log(result.getSignInUserSession()?.getRefreshToken());
      }
      this.props.navigation.replace('ChangePassword');
    }
  ).catch(
    (error) => {
      console.log('################# SignIn Error :');
      console.log(error);
    }
  )
   } catch (exception) {
  console.log(exception);
     console.log('################# Exception in SignIn API call');
    }
Run Code Online (Sandbox Code Playgroud)

无法弄清楚出了什么问题。

 [ERROR] 27:54.153 AuthError - 
        Error: Amplify has not been configured correctly. 
        The configuration object is missing required auth properties. 
        Did you run `amplify push` after adding auth via `amplify add auth`?
        See https://aws-amplify.github.io/docs/js/authentication#amplify-project-setup for 
   more information
Run Code Online (Sandbox Code Playgroud)

请告诉我为什么当我在 iOS 中运行时上面的代码显示错误。

小智 0

更新 Amplify 版本后,我遇到了同样的问题。我删除了node_modues文件夹和package-lock.json。我运行了“npm install”并修复了它。