繁体   English   中英

AWS/Cognito,通过 CDK 创建用户池时,如何设置标准属性的字符串长度。 我想为全名添加最小/最大长度

[英]AWS/Cognito, when creating a user pool through CDK, how can I set string length for standard attributes. I want to add min/max length for fullname

AWS/Cognito 在通过 CDK 创建用户池时,如何设置标准属性的字符串长度。

我试图找到它,但没有运气,因为没有。 我正在使用 Typescript。

我的用户池如下所示:

const userPool = new cognito.UserPool(this, `name-of-user-pool-${stage}`, {
  signInAliases: {
    email: true,
    username: false,
  },
  standardAttributes: {
    fullname: { required: true, mutable: true },
  },
  passwordPolicy: {
    minLength: 8,
    requireDigits: true,
    requireLowercase: true,
    requireUppercase: true,
    requireSymbols: true,
  },
  selfSignUpEnabled: true,
  userVerification: {
    emailSubject: 'Verify your email !',
    emailBody: 'Thank you for signing up to our app! Your verification code is {####}',
    emailStyle: cognito.VerificationEmailStyle.CODE,
  },
  accountRecovery: cognito.AccountRecovery.EMAIL_ONLY,
});

我不确定这样做是否有不明确的含义,但您可以创建一个具有长度限制的自定义属性并改用它。 如果使用与标准属性相同的名称(假设未使用),CDK 不会抱怨。

const name: ICustomAttribute = {
  bind: (): CustomAttributeConfig => 
    mutable: true,
    dataType: 'String',
    stringConstraints: {
      maxLen: 30,
      minLen: 10
    }
  })
}

const userPool = new UserPool(this, 'TestUserPool', {
  ...
  customAttributes: {
    name
  }
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM