4
Ionic App不發送授權標頭。即使授權標頭列在允許的標題中,標題值也不存在。 我使用快遞的NodeJS和MongoDB作爲後端這裏是我的CORS頭
<code>
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods',
'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Expose-Headers',
'X-Authorization-Token, Authorization');
res.header('Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept, Authorization'
);
And Here Is My AuthInterceptor
return {
request: function(config) {
var token = authToken.getToken();
if (token) {
config.headers.Authorization = 'Bearer ' + token;
}
return config;
},
response: function(response) {
return response;
}
};
My $http
return $http(options).success(function(response) {
self.currUser = response.profile;
if (_.contains(response.profile.roles, 'admin') ||
!((_.contains(response.profile.roles, 'lecturer')) || (_.contains(
response.profile.roles, 'evaluator')))) {
$state.go('admin');
}
})
</code>
如果不顯示用於設置標題的代碼 – charlietfl
是'authToken.getToken()'同步?它是否會返回有效的令牌?如果它是異步的,你有一個問題 – charlietfl
沒有它來自本地存儲 – faridah1396