【发布时间】:2015-09-29 17:10:59
【问题描述】:
我正在尝试让跨域前端与托管在另一个域的 SailsJS 后端正常运行。具体来说,是用户身份验证和凭据被破坏。
在正常的POST, GET, 等类型的数据库行为下,一切都正常运行。例如,已经可以注册新用户。
但是,用户登录后,身份验证步骤失败,我收到401 Unauthorized。
这是控制台告诉我的:
[Object, "post", "login", "https://small-change-api.herokuapp.com/user/login"]
User logged in: Object {firstName: "John", lastName: "Does", email: "test@work.com", activated: true, superUser: false…}
-- 好 :)
[Array[0], "get", "authenticated", "https://small-change-api.herokuapp.com/user/authenticated"]
GET https://small-change-api.herokuapp.com/user/authenticated 401 (Unauthorized)
--不好
现在,所有这些都 100% 在本地运行,但托管在 Heroku 上,出了点问题:/
以下是一些相关的服务器端配置:
这是在文件config/cors.js
module.exports.cors = {
allRoutes: true,
origin: 'https://thefrontendorigin.com',
credentials: true,
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH',
headers: 'content-type,Access-Control-Allow-Origin'
};
在前端withCredentials设置为true:
RestangularProvider.setDefaultHttpFields({ withCredentials: true });
我还需要做些什么来做对?看起来它应该可以工作......:/
如果我需要提供更多信息,请告诉我!
谢谢。
附:两个 GH 存储库现在都是公开的,所以让我分享一下。
【问题讨论】:
标签: authentication heroku sails.js