Node.js Parse.com根据用户是否';s是否已登录(Express server)
我正在使用Parse.com Express server构建一个web应用程序,我想根据用户是否登录服务器端来重定向用户Node.js Parse.com根据用户是否';s是否已登录(Express server),node.js,redirect,express,parse-platform,Node.js,Redirect,Express,Parse Platform,我正在使用Parse.com Express server构建一个web应用程序,我想根据用户是否登录服务器端来重定向用户 有没有一种简单的方法可以做到这一点?这就是我使用Passport.js处理会话并为我加载用户的方法。 如果您使用的是另一种方法,则可能需要测试与If(req.user)不同的内容 function redirectIfAnon(req, res, next){ if(req.user){ return next(); // go to next handling
有没有一种简单的方法可以做到这一点?这就是我使用Passport.js处理会话并为我加载用户的方法。 如果您使用的是另一种方法,则可能需要测试与
If(req.user)
不同的内容
function redirectIfAnon(req, res, next){
if(req.user){
return next(); // go to next handling function in middleware chain
} else {
var dest = encodeURIComponent(req.originalUrl);
res.redirect('/login?bounce='+dest)
// careful about redirect loops here... if you apply this middleware to /login,
// and an anonymous user visits /login, it will keep redirecting to /login
};
};
app.get('/test',
redirectIfAnon,
function(req, res){
// req.user is guranteed to be populated if we get here
parse.fetch(req.user.parseID, function(err...){
...
// or something. ive never used parse.com
res.render('parseResults');
})
});