You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用AWS Amplify Authenticator与Cognito:用户池登录类型为邮箱时是否自动变更标签?

AWS Amplify Authenticator 与 Cognito 邮箱登录的标签适配问题
  • 结论:不会自动检测并修改标签。Amplify Authenticator组件默认不会根据Cognito用户池的登录类型配置,自动将登录框的“username”标签替换为“email”。
  • 手动调整方案:
    1. 自定义登录组件:通过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>
        );
      }
      
    2. 覆盖国际化词汇:利用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 07:03:10