[英]Handle Email Verification Check with auth0/nextjs
我正在使用库 auth0/nextjs。 我正在尝试处理 email 验证。 我可以访问 email_verification 变量。 如果未通过验证,它将重定向到“please-verifiy-your-email”页面。
目前我正在使用 auth0/nextjs 提供的 handleCallback 方法。
代码:
const afterCallback = (req, res, session, state) => {
if (!session.user.email_verified) {
res.status(200).redirect('/please-verifiy-your-email')
}
return session;
};
export default auth0.handleAuth({
async login(req, res) {
try {
await auth0.handleLogin(req, res, {
authorizationParams: {
audience: 'https://dev-okz2bacx.us.auth0.com/api/v2/',
scope: 'openid profile email read:branding'
},
returnTo: "/dashboard"
});
} catch (error) {
res.status(error.status || 400).end(error.message);
}
},
async callback(req, res) {
try {
await auth0.handleCallback(req, res, { afterCallback });
} catch (error) {
res.status(error.status || 500).end(error.message);
}
}
});
我如何确保用户仍处于登录状态,以获取他的 email 进行重新发送或更改他的 email 的可能性。
他还需要重新注册的机会,因为当我使用未经验证的 email 登录后调用“api/auth/login”时,它会自动重定向到“please-verifiy-your-email”。 我猜 session 没有被杀死,即使我没有机会再次注册,auth0 也会返回重定向。
如果我得到一些输入会非常酷:slight_smile:
编辑:如果我可以登录用户然后它会重定向到“please-verifiy-your-email”,它将解决问题。 我将能够获得他的 email 地址,以及重新发送验证等其他功能的名称。 现在我调用“api/auth/me”我得到:
{"error":"not_authenticated","description":"The user does not have an active session or is not authenticated"}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.