AuthError - 错误:未正确配置放大

Sah*_*sha 18 amazon-web-services reactjs aws-amplify

首先,我使用amplify configure. 我是在AWS Amplify 文档的帮助下完成的。然后我成功地将身份验证添加到我的放大项目中,使用amplify add authamplify push。我遵循了AWS - Authentication with Amplify Doc中的所有步骤

我的长App.js这样

import React from 'react';
import { withAuthenticator, AmplifySignOut } from '@aws-amplify/ui-react';
import Amplify, { Auth } from 'aws-amplify';
import awsconfig from './aws-exports';

Amplify.configure(awsconfig);


const App = () => (
    <div>
        <AmplifySignOut />
        My App
    </div>
);

export default withAuthenticator(App);
Run Code Online (Sandbox Code Playgroud)

但是当我尝试时npm start,它显示以下错误, AuthError - 错误:Amplify 配置不正确。

Sah*_*sha 23

我在这个github-issue 中找到了这个问题的解决方案

修复很简单。扩增出的文档不告诉你加载的CONFIGSaws-exportsAuth module

在 中添加这行简单的代码App.js,为我解决了这个问题。

import Amplify, { Auth } from 'aws-amplify';
import awsconfig from './aws-exports';

Amplify.configure(awsconfig);

// >>New - Configuring Auth Module
Auth.configure(awsconfig);
Run Code Online (Sandbox Code Playgroud)

  • 就我而言,我必须重新安装依赖项才能工作(`npm un aws-amplify @aws-amplify/ui-react` / `npm i aws-amplify @aws-amplify/ui-react`) (3认同)

小智 11

  • npm un aws-amplify @aws-amplify/ui-react
  • npm i aws-amplify @aws-amplify/ui-react

这对我有用。谢谢@伊格纳西奥


小智 11

我认为由于安装的 Amplify 模块之间的不一致,在各种 Amplify 模块版本下会出现此问题。在我的情况下,重新安装如下多次解决了它。

npm uninstall --save aws-amplify @aws-amplify/ui-react @aws-amplify/ui-components

npm install --save aws-amplify @aws-amplify/ui-react @aws-amplify/ui-components

如果使用的话,有一种情况需要重新安装@aws-amplify/ui-components


Fur*_*uan 5

我在世博会上做待办事项应用程序,并遇到了同样的问题。我必须为配置文件添加正确的路径。路径不同aws-exports,文档中未提及。我的示例代码如下

import awsconfig from './src/aws-exports'

Amplify.configure(awsconfig);
Auth.configure(awsconfig);

import { createTodo } from './src/graphql/mutations'
import { listTodos } from './src/graphql/queries'
import { withAuthenticator } from 'aws-amplify-react-native'
Run Code Online (Sandbox Code Playgroud)