【问题标题】:React Native AWS Amplify AuthError : Amplify has not been configured correctlyReact Native AWS Amplify AuthError:未正确配置 Amplify
【发布时间】:2021-01-30 02:51:27
【问题描述】:

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

我已按照 iOS pod install 的这些步骤来设置 Amplify 库 https://docs.amplify.aws/lib/auth/start/q/platform/js#configure-your-application

我已经在 iOS 中安装了所有与 https://www.npmjs.com/package/react-native-config 和放大库相关的 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');
    }

无法找出问题所在。

 [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

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

【问题讨论】:

    标签: javascript ios react-native amazon-cognito aws-amplify


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-12-16
      • 2021-11-20
      • 2020-12-15
      • 1970-01-01
      • 2023-03-22
      • 2019-08-30
      • 2020-08-21
      • 2023-03-13
      • 2020-01-08
      相关资源
      最近更新 更多