繁体   English   中英

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

[英]React Native AWS Amplify AuthError : Amplify has not been configured correctly

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

我已经按照 iOS pod install 的这些步骤来设置放大库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 中运行时上面的代码显示错误。

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

我对 android 的 react-native-config 设置有问题。 我忘记为 android 做这个额外的步骤 我的配置未定义

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM