在使用 Amplify UI React 库中的认证组件时,如果 AuthStatus 的状态无法从 “configuring” 更改,可能是因为未正确配置 Auth 组件或未授权。
以下是一个示例代码片段,展示如何正确配置并授权 Auth 组件:
import { withAuthenticator } from 'aws-amplify-react';
import Amplify from 'aws-amplify';
import awsconfig from './aws-exports';
Amplify.configure(awsconfig);
const App = () => {
return (
My App
);
};
export default withAuthenticator(App, {
includeGreetings: true,
signUpConfig: {
hiddenDefaults: ['phone_number'],
},
});
在上面的代码中,我们首先导入 withAuthenticator 函数和 Amplify 应用程序的配置。然后,我们使用 Amplify.configure 函数配置 Amplify 应用程序。最后,我们将 withAuthenticator 函数应用于我们的应用程序组件,并提供配置选项,如包含问候语和隐藏电话号码。
确保按照 Amplify 文档中的说明进行正确的配置和授权,以确保 AuthStatus 状态可以更改。