Mean.io:重定向到身份验证后所需的路线 [英] Mean.io: Redirect to desired route after authentication

查看:134
本文介绍了Mean.io:重定向到身份验证后所需的路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在需要登录一个mean.io应用中的一些路线和我使用

I have some routes in a mean.io app that require login and I use the

resolve: {loggedIn: checkLoggedin}.

如何重定向到该路由当用户进行身份验证,这样,用户就不会最终回到家乡'/'的网址。

How do I redirect back to that route when the user is authenticated, so that the user don't end up back at the home '/' url.

推荐答案

我做的是修改 checkLoggedIn 函数,这样当它重定向到的方式 /登录,它通过所谓的查询字符串参数重定向与重定向到的路径。然后,在 /登录路线,添加以下功能:

The way I did it was to modify the checkLoggedIn function so that when it redirects to /login, it passes a query string parameter called redirect with the path to redirect to. Then, in the /login route, add the following function:

app.route('/login')
    .all(passport.authenticate('basic'), function(req, res) {
        res.redirect(req.query.redirect);
    });

这篇关于Mean.io:重定向到身份验证后所需的路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆