【问题标题】:Angular AWS Amplify authenticator extrra fieldsAngular AWS Amplify 身份验证器额外字段
【发布时间】:2019-03-17 17:27:02
【问题描述】:

我正在尝试使用带有 Angular 的 AWS Amplify 进行 Cognito 身份验证,我面临的问题是,当我调用组件时:

<amplify-authenticator></amplify-authenticator>

它没有包含我在 Cognito 中标记为必填的所有注册字段,因此它总是返回错误,例如:缺少字段名称,例如

所以我的问题是,如果他们没有返回我标记为必填的某些字段,我该如何添加它,而无需更改组件本身的来源。

PS:我使用的是 Angular,aws-amplify-angular。

【问题讨论】:

    标签: angular amazon-cognito aws-amplify


    【解决方案1】:

    在撰写此评论时,Angular 或 React(仅限 Vue)的完整版本可能无法实现,但 beta 版本确实有一些选项。

    您可以通过添加以下包来获取测试版:

    npm install aws-amplify-angular@beta
    

    更新放大验证器组件如下所示:

    <amplify-authenticator [signUpConfig]="signUpConfig" ></amplify-authenticator>
    

    signupConfig 将在您的组件中设置,看起来像这样:

    const signUpConfig = {
      header: 'Welcome!',
      defaultCountryCode: '46',
      hideDefaults: true,
      signUpFields: [
        {
          label: 'Username',
          key: 'username',
          required: true,
          displayOrder: 1,
          type: 'string',
        },
        {
          label: 'Password',
          key: 'password',
          required: true,
          displayOrder: 2,
          type: 'password',
        },
        {
          label: 'Email',
          key: 'email',
          required: true,
          displayOrder: 3,
          type: 'email',
        },
        {
          label: 'Name',
          key: 'name',
          required: true,
          displayOrder: 4,
          type: 'string',
        },
        {
          label: 'Family name',
          key: 'family_name',
          required: true,
          displayOrder: 5,
          type: 'string',
        },
        {
          label: 'Phone number',
          key: 'phone_number',
          required: false,
          displayOrder: 6,
          type: 'string',
        }
      ]
    };
    

    详情请看以下两个链接:

    https://github.com/aws-amplify/amplify-js/issues/1911#issuecomment-437090097 https://haverchuck.github.io/docs/js/ionic#signup-configuration

    【讨论】:

    • 太棒了,我昨天也看到了关于 reinvent 的内容! ;) 谢谢!
    • hideDefaults 应该是hideAllDefaults
    猜你喜欢
    • 2019-08-27
    • 2021-03-17
    • 2021-05-17
    • 1970-01-01
    • 2020-09-08
    • 2018-12-17
    • 1970-01-01
    • 2019-02-15
    • 2019-04-20
    相关资源
    最近更新 更多