使用AWS Amplify Authenticator与Cognito:用户池登录类型为邮箱时是否自动变更标签?
AWS Amplify Authenticator 与 Cognito 邮箱登录的标签适配问题
- 结论:不会自动检测并修改标签。Amplify Authenticator组件默认不会根据Cognito用户池的登录类型配置,自动将登录框的“username”标签替换为“email”。
- 手动调整方案:
- 自定义登录组件:通过
components属性重写SignIn表单,直接修改输入框标签。示例代码:import { Authenticator, View, TextField } from '@aws-amplify/ui-react'; import '@aws-amplify/ui-react/styles.css'; const CustomSignIn = ({ signIn, formFields }) => { return ( <View> <TextField {...formFields.username} label="邮箱" /> <TextField {...formFields.password} label="密码" /> <button onClick={signIn}>登录</button> </View> ); }; export default function App() { return ( <Authenticator components={{ SignIn: CustomSignIn }}> {({ signOut, user }) => ( <main> <h1>欢迎, {user.username}</h1> <button onClick={signOut}>退出登录</button> </main> )} </Authenticator> ); } - 覆盖国际化词汇:利用Amplify的i18n功能替换默认文本。示例代码:
import { I18n } from '@aws-amplify/core'; import { translations } from '@aws-amplify/ui-react'; I18n.putVocabularies(translations); I18n.setLanguage('zh'); // 替换username标签文本 I18n.putVocabulary('zh', { 'SignIn.username': '邮箱', });
- 自定义登录组件:通过
内容的提问来源于stack exchange,提问作者James
相关产品推荐
相关产品推荐

