我正在开发React/Redux SPA应用程序,希望进行授权。我有使用devise_token_auth gem的Rails后端,并且(在React应用程序中)需要保存由后端响应给我的令牌。然而,response.headers
中没有可用的令牌。为什么?CORS已正确设置在后端,所以我确定这不是问题所在。请查看代码和截图:
let config = {
method: 'POST',
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(creds) // { email: 'asd@example.org', password: 'asdasdasd' }
}
return dispatch => {
dispatch(requestLogin(creds))
return fetch('http://localhost:3000/auth/sign_in', config)
.then((response => {
response.headers.forEach((el) => console.log(el))
}))
}
console.log:
证明浏览器看到了头部信息: