要解决“AWS Amplify 针对 React 的身份验证自定义 UI 被隐藏了”的问题,你可以尝试以下步骤:
npm install aws-amplify aws-amplify-react
import Amplify from 'aws-amplify';
import awsConfig from './aws-exports';
import { withAuthenticator } from 'aws-amplify-react';
Amplify.configure(awsConfig);
Authenticator 组件来创建自定义 UI。以下是一个示例:import React from 'react';
import { Authenticator } from 'aws-amplify-react';
class CustomAuthenticator extends Authenticator {
render() {
return (
Custom Auth UI
{/* 在这里添加你的自定义身份验证 UI */}
);
}
}
export default withAuthenticator(CustomAuthenticator);
withAuthenticator 高阶组件将自定义的身份验证 UI 组件与应用程序的其他组件包装起来:function App() {
// 应用程序的其他组件
return (
{/* 应用程序的其他组件 */}
);
}
export default withAuthenticator(App);
这样,你的自定义身份验证 UI 组件将被作为应用程序的一部分显示出来。你可以在 CustomAuthenticator 组件中添加自定义 UI 的代码来满足你的需求。