簡體   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