我正在本地测试基于 MEAN 堆栈的应用程序。对于身份验证功能,我使用的是 passportjs。
但是在调试时我每次重启服务器都必须登录。
是否有一个简单的配置,我可以在不更改我的大部分代码的情况下禁用 passportjs。
最佳答案
我用下面的代码让它工作。只需进行以下更改即可跳过我的应用程序的身份验证。
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');
};
希望对大家有帮助。
关于node.js - 如何在本地禁用 passportjs 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28525954/