【问题标题】:Cannot find name 'attributes'. Amplify Auth找不到名称“属性”。放大认证
【发布时间】:2020-08-10 12:59:10
【问题描述】:

我已使用 amplify add auth 向我的 Angular 应用程序添加了授权。 之后我添加了

"requiredAttributes": [
    "email",
    "custom:firstName",
    "custom:lastName"
],

到 amplify/backend/auth/XXX/parameters.json

  Schema:

    -
      Name: email
      Required: true
      Mutable: true

    -
      AttributeDataType: "String"
      Mutable: true
      Name: firstName
      StringAttributeConstraints:
        MaxLength: 256
        MinLength: 1

    -
      AttributeDataType: "String"
      Mutable: true
      Name: lastName
      StringAttributeConstraints:
        MaxLength: 256
        MinLength: 1

到 amplify/backend/auth/XXX/XXX-cloudformation-template.yml

之后amplify push

我可以在控制台中看到这些自定义字段:

但是当我尝试发送这样的自定义字段时:

  import { Auth } from 'aws-amplify';

  ...

  signUp(email, password, firstName, lastName): Observable<any> {
    return fromPromise(Auth.signUp(
      email,
      password,
      attributes: {
        "custom:firstName": firstName,
        "custom:lastName": lastName
      }
    ));
  }

TypeScript 编译器抛出此错误:

找不到名称'attributes'.ts

应该是:

signUp(params: string | SignUpParams, ...restOfAttrs: string[]): Promise&lt;ISignUpResult&gt;

【问题讨论】:

    标签: angular typescript amazon-web-services amazon-cognito aws-amplify


    【解决方案1】:

    这是我的解决方法:

      signUp(username, password, firstName, lastName): Observable<any> {
        const signUpParams: any = {
          username,
          password,
          attributes: {
            'custom:firstName': firstName,
            'custom:lastName': lastName
          }
        };
        return fromPromise(Auth.signUp(
          signUpParams
        ));
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-24
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多