0
在我的角度應用程序,我有一個名爲「authInterceptor」一個$ HTTP請求攔截器,我創造這樣的:)
.factory('authInterceptor', function ($q, $window, EXT_API_BASE, $injector) {
return {
request: function (config) {
if (config.url.indexOf(EXT_API_BASE) !== -1){
var Auth = $injector.get('Auth');
if(Auth.user && Auth.user.token){
config.headers.Authorization = 'Web ' + Auth.user.token;
}
}
return config;
}
}});
它被登記在的.config(:
$httpProvider.interceptors.push('authInterceptor');
如您所見,我的授權標頭綁定到Auth.user.token值。當我的用戶登錄時,此值可用。
然後發送標頭以調用我的api。
我面臨的問題是...當用戶在我的角度應用程序中註銷時,即使我已經刪除了Auth.user.token,授權標頭仍然正在發送。
在頁面的硬刷新上,授權標頭然後完全刪除。
如何確保'authInterceptor'在用戶註銷時註冊令牌值的更改?