0
在路由和呈現網站之前我想檢查用戶是否已通過身份驗證並具有某種類型。 「中間件」如下所示:Node.js中間件身份驗證變量
function isAuthenticated(req,res,next,required_type){
if(Parse.User.current()){
Parse.User.current().fetch().then(function(fetchedUser){
var type = fetchedUser.get("type");
if(type == required_type){
return next();
}else{
res.redirect("/login");
}
}, function(error){
res.redirect("/login");
});
}else{
res.redirect("/login");
}
}
這部分看起來很公平和容易。這裏是我嘗試之前,我的路由使用中間件:
app.get('/dashboard_client',isAuthenticated, dashboard_client_view_controller.displayView);
我的問題是,我該如何設置required_type變量,因爲Node.js的莫名其妙知道怎麼弄,找到REQ,資源和未來變數。謝謝你回答這樣一個愚蠢的問題,我想這個問題很明顯。
'app.get( '/ dashboard_client /:requiredtype',isAuthenticated,dashboard_client_view_controller .displayView);'然後調用GET/dashboard_client/requiredtype,其中requiredtype是您的類型。 – 2015-04-01 13:59:10