Passport 和 SailsJS,如何让 isAuthenticated() 测试通过

Passport and SailsJS, how to get isAuthenticated() test to pass

当用户尝试登录时,我的代码总是失败:

isAuthenticated: function (req, res) {
    if (req.isAuthenticated()) { return res.json(req.user); }
    else { return res.send(401); }
},

失败 并且我在控制台中得到 GET http://localhost:1337/user/authenticated 401 (Unauthorized),即使用户输入了正确的电子邮件和密码。

代码中的哪个位置使该测试通过?

我有相关的 Whosebug 问题以及更多信息

问题是我的前端应用程序与后端应用程序的来源不同,因此 AJAX 请求将不包含会话 cookie,并且 req.isAuthenticated() 永远不会 return是的。

使用 withCredentials 选项强制执行。

$http({ withCredentials: true, ... })