【发布时间】:2015-03-30 12:16:28
【问题描述】:
我有如下端点:
app.post(api + '/channels/:channel_id/albums', user.ensureAuthenticated, album.create);
app.get(api + '/channels/:channel_id/albums/published', user.ensureAuthenticated,album.publishedAlbums);
app.get(api + '/channels/:channel_id/albums', user.ensureAuthenticated, album.findAll);
一切正常,但是将 user.ensureAuthenticated 放入每个端点对我来说很烦人,有没有什么方法可以一次性放入 user.ensureAuthentication ?
例如:Laravel 有这样的选项,比如 beforeAuth 你做一个 if 和里面你把所有你想要保护的端点。
例如:
if(user.ensureAuthenticated){
// endpoints declariations
}else{
// redirect to login
}
感谢
【问题讨论】:
标签: javascript node.js passport.js