【以下的问题经过翻译处理】 你好,
为了能够自定义消息和登陆页面,我已经按照以下程序成功实现了流程
https://medium.com/@jacobjoy/redirect-user-using-amazon-cognito-confirmation-url-d8ccb11bac75
但是,当用户通过单击验证电子邮件中的链接确认他的电子邮件时,我需要更新我的数据库
因此,我创建了另一个在“Post confirmation”时触发的 lambda
但是现在,如果用户单击电子邮件中的链接,他将被重定向到错误页面,即使他的结果在用户池中得到确认并且数据库已正确更新。
如果我使用“Post confirmation”触发器删除 lambda,一切正常。
如何实现用户点击确认链接成功后更新数据库的目的?
这是带有“Post confirmation”触发器的 lambda:
const axios = require("axios");
exports.handler = async (event, context, callback) => {
console.log("Authentication successful");
console.log("Trigger function =", event.triggerSource);
console.log("User pool = ", event.userPoolId);
console.log("App client ID = ", event.callerContext.clientId);
console.log("User ID = ", event.userName);
console.log("event = ", event.request.userAttributes.email);
const data = {
email:event.request.userAttributes.email,
key:process.env.KEY
}
await axios.post(`${process.env.BASE_URL}/api/ac/user-confirm`,data )
callback(null, event);
};
而这是在 Cognito 中确认用户的 Lambda,如上述教程中所述
“use strict”;
var AWS = require("aws-sdk");
AWS.config.setPromisesDependency(require("bluebird"));
var CognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider({
apiVersion: “2019-11-07”,
region: process.env.REGION,
});
const axios = require("axios");
exports.handler = (req, context, callback) => {
console.log(req);
const confirmationCode = req.code;
const username = req.username;
const clientId = req.clientId;
let params = {
ClientId: clientId,
ConfirmationCode: confirmationCode,
Username: username,
};
//Validating the user
let confirmSignUp =
CognitoIdentityServiceProvider.confirmSignUp(params).promise();
//Returning the redirect url
confirmSignUp
.then(async (data) => {
context.succeed({
location: process.env.POST_REGISTRATION_VERIFICATION_REDIRECT_URL,
});
})
.catch((error) => {
//callback(error.message);
console.log("ERROR: ", error);
if (error.code == "ERR_BAD_RESPONSE") {
context.succeed({
location: process.env.POST_REGISTRATION_VERIFICATION_REDIRECT_URL,
});
} else {
context.succeed({
location: process.env.POST_REGISTRATION_VERIFICATION_INVALID_LINK,
});
}
});
};