我在我的本地测试我的基于MEAN堆栈的应用程序。对于身份验证功能,我使用的是passportjs。
但是在调试时我必须每次重启服务器时登录。
是否有一个简单的配置,我可以做的是禁用passportjs而不用我的大部分代码。
答案 0 :(得分:2)
我使用了以下代码。只需要进行更改即可跳过我的应用的身份验证。
var isAuthenticated = function (req, res, next) {
var isAuthorised = req.isAuthenticated();
// TODO remove followoing on production code
// Set user as authorised in local
isAuthorised = true;
req.user = {};
// id of whichever account you want to load
req.user._id = '12345whatever';
if (isAuthorised) {
return next();
}
// if the user is not authenticated then redirect him to the login page
res.redirect('/login');
};
希望它有所帮助。