[英]Including the expiration date/time in AWS Cognito verficication email
我發現使用 AWS Cognito 通過我的網站創建賬戶時,驗證碼的有效期為 24 小時。 我正在使用 AWS CDK 將我的堆棧部署到我的 AWS 環境。 在我的主cdk.ts文件中,我有以下變量:
const datetime: Date = new Date(new Date().getTime() + (24 * 60 * 60 * 1000));
export const date: string = datetime.toLocaleDateString();
export const time: string = datetime.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
在我的 Cognito 堆棧文件中,我有一個 HTML 模板,用於用戶在注冊時收到的 email,其中包括代碼的有效期。 現在我已經能夠在此 HTML 模板中成功引用它們,但是,日期和時間不正確,因為它們是從我部署堆棧時起 +24 小時,而不是從發送 email 時起 +24 小時。 我將如何 go 使其從 email 創建日期算起 24 小時?
您可以利用 Cognito 觸發的事件並使用 lambda 生成 email 正文。
以下是用戶池的 CDK 設置示例:
const userPool = new UserPool(this, 'UserPool', {
selfSignUpEnabled: true, // Allow users to sign up
autoVerify: { email: true }, // Verify email addresses by sending a verification code
signInAliases: { email: true }, // Set email as an alias
lambdaTriggers: {
customMessage: cognitoMailTransformerLambda, // For custom emails
postConfirmation: cognitoEventDispatcherLambda // Can be used for post confirm events such as setting up a database etc
},
customAttributes: {
...
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.