有很多方法可以在keystone中實現自己的身份驗證和帳戶管理方法,因爲它基於express.js。
然後,您可以添加一個「中間件」函數數組到路由,這些路由在將請求傳遞到控制器之前將會運行。
e.g 路線中間件之前加入
app.get('/admin', routes.views.userAdmin);
中間件功能
function isAuthenticated(req, res, next) {
// do any checks you want to in here
// CHECK THE USER STORED IN SESSION FOR A CUSTOM VARIABLE
// you can do this however you want with whatever variables you set up
if (req.user.authenticated)
return next();
// IF A USER ISN'T LOGGED IN, THEN REDIRECT THEM SOMEWHERE
res.redirect('/');
}
路線與中間件加入
app.get('/admin', isAuthenticated, routes.views.userAdmin);
這是一個非常寬泛的問題,所以我建議你去決定你想自己做的最好方法,因爲每個人都有自己的個人喜好。您想要的搜索字詞是「express middleware authentication」。很多人使用PassporJS http://passportjs.org/
希望幫助:)