簡體   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