【问题标题】:AWS Cognito Amplify Authentication and Angular UI ComponentsAWS Cognito Amplify 身份验证和 Angular UI 组件
【发布时间】:2019-08-27 12:05:30
【问题描述】:

您好,我正在尝试使用内置的 Angular 组件进行身份验证。 我用 Amplify 创建了 Cognito 和 API。 Cognito 用户池无法更改。 这是一个屏幕截图,您也可以在其中看到设置:

我已经像这样初始化组件:

  <ion-content padding>  
      <amplify-authenticator [signUpConfig]="signUpConfig" framework="ionic"></amplify-authenticator>
  </ion-content>

我的课程包含这个用于 signUpConfig:

  constructor(
    public events: Events,
    public amplifyService: AmplifyService,
    public router: Router
  ) {
    this.authState = { signedIn: false };
    this.signUpConfig = {
      header: "SignUp",
      defaultCountryCode: '30',
      hideAllDefaults: true,
      signUpFields: [
        {
          label: 'Mobile-Username',
          key: 'username',
          required: true,
          displayOrder: 1,
          type: 'string'
        },
        {
          label: 'Mobile',
          key: 'phone_number',
          required: true,
          displayOrder: 2,
          type: 'string'
        },
        {
          label: 'Password',
          key: 'password',
          required: true,
          displayOrder: 3,
          type: 'password'
        },
        {
          label: 'Email',
          key: 'email',
          required: true,
          displayOrder: 4,
          type: 'email'
        },
        {
          label: 'Name',
          key: 'name',
          required: true,
          displayOrder: 5,
          type: 'string'
        },
        {
          label: 'Surname',
          key: 'family_name',
          required: true,
          displayOrder: 6,
          type: 'string'
        },
        {
          label: 'Address',
          key: 'address',
          required: true,
          displayOrder: 7
        },
        {
          label: 'Gender',
          key: 'gender',
          required: true,
          displayOrder: 8
        }
      ]

    };
  }

不幸的是,我必须包括

        {
          label: 'Mobile-Username',
          key: 'username',
          required: true,
          displayOrder: 1,
          type: 'string'
        },

为了使用手机号码填充用户名,因为 Cognito UserPool 正在等待 usernamemobile number,尽管从设置中可以清楚地看到我只需要手机作为我的用户名。

如果我离开我的signUpFields 的第一个条目,那么我总是会从服务器收到username cannot be empty 的错误。

我应该做什么,尤其是现在我无法对我的用户池进行任何更改。我相信这是因为我使用 Amplify CLI 来设置它。

【问题讨论】:

    标签: angular ionic-framework amazon-cognito aws-amplify


    【解决方案1】:

    您是否尝试在attributes 参数中传递username?或者在属性参数中尝试preferred_username 而不是username

    Auth.signUp({
        username,
        password,
        attributes: {
          'username': username // HERE or try 'preferred_username': username
        },
        validationData: []  //optional
        }).then().catch()
    
    

    根据文档

    如果用户名字符串是有效的电话号码格式,用户池会自动使用用户名值填充用户的 phone_number 属性。 您可能不需要添加上面的代码。

    链接:https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-aliases

    【讨论】:

    • 在我的注册配置中我添加了这个:signUpFields: [ { label: 'Mobile number', key: 'username', required: true, displayOrder: 1, type: 'string' },并且确实使用户名成为手机号码,但是这样我就失去了如果密钥是phone_number 的特殊渲染。我的意思是国家代码的弹出窗口。此外,从您发布的先前代码中,如果我的模板中只有 ,我应该如何获取对用户名和密码的引用?
    猜你喜欢
    • 2021-02-28
    • 2018-05-22
    • 2018-01-29
    • 2020-01-01
    • 2019-02-15
    • 2019-04-20
    • 2016-08-20
    • 2016-06-25
    • 1970-01-01
    相关资源
    最近更新 更多