【发布时间】:2020-08-18 20:24:10
【问题描述】:
它是一个开放的代码,从通过电子邮件结束给用户的电子邮件开始,当他们打开链接时,它会引导到端点的用户。
函数结束时我想将用户重定向到一个新页面,但是重定向不起作用,为什么不起作用?
async getToken(req, res) {
// const { token } = req.params;
let { access_token } = req.query;
access_token = access_token.replace(/\s/g, '');
let decoded;
try {
decoded = jwt.verify(access_token, process.env.JWT_ACCOUNT_ACTIVATION);
const email_consulted = decoded.email; // you are returning a success response but you havent finished the process yet. Usually the success is sent on the end of the process
let select = await pool.query(
`SELECT User_email FROM user WHERE User_email='${email_consulted}'`
);
// console.log(select);
if (select.length > 0) {
return res.json({
success: false,
code: 400,
message: "Email ya existe"
});
}
const result = await pool.query(
`INSERT INTO user (User_email) VALUES ('${email_consulted}')`
);
let selectid = await pool.query(
`SELECT ID_user FROM user WHERE User_email='${email_consulted}'`
);
const id = selectid[0].ID_user
const token = jwt.sign(
{ id },
process.env.JWT_ACCOUNT_ACTIVATION,
{expiresIn: '30d' }
)
res.cookie("_$",token);
res.json({
sucess: true,
code: 201,
message: "Usuario añadido exitosamente",
token
});
return window.location.replace("http://seth.com/dashboard.html?ftime=0");
// if (select != "") {
// const result = await pool.query(`INSERT INTO user (User_email) VALUES (${email_consulted})`);
// }
} catch (err) {
return res.json({ message: "Internal server error" });
}
}
【问题讨论】:
-
你用的是快递吗??
标签: javascript node.js json npm