gpt4 book ai didi

javascript - Passport JS :redirect to another url with data

转载 作者:太空宇宙 更新时间:2023-11-04 01:47:11 25 4
gpt4 key购买 nike

从 Passportjs 文档中,我可以重定向到 URL

app.post('/login',
passport.authenticate('local', { successRedirect: '/',
failureRedirect: '/login' }));

是否可能successRedirect应该是另一个不同的域假设成功登录后,我的身份验证位于 www.auth.com 中,我想使用 www.auth.com 中的数据重定向到 www.customer.com/callback

这实际上就像 Facebook 身份验证,在成功登录 facebook POST 数据到回调 URL 后使用回调 URL

最佳答案

app.get('/login', function(req, res) { //will handle if user fails to enter valid credentials
return res.render('login', {
message: 'Login Page Renderd...'
});
});

app.post('/login', passport.authenticate('local', {
successRedirect: '/profile', //will be redirected to `/profile` route after successful login
failureRedirect: '/login' //will be redirected to `/login` route for failure
}));

app.get('/profile', function(req, res) { //will handle if user enter valid credentials means user logged in successfully
return res.status(200).send('User Logged in successfully...');
});

Passport-Facebook我们需要定义身份验证成功和失败的回调 url,与 Passport-Local 相同

关于javascript - Passport JS :redirect to another url with data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51007257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com