在我的 Angular 应用程序中,我创建了一个名为“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');
如您所见,我的 Authorization 标头绑定到 Auth.user.token 值。当我的用户登录时,此值可用。
然后发送标头用于对我的 api 的任何调用。
我面临的问题是......当用户在我的角度应用程序中注销时,即使我已经删除了 Auth.user.token,授权标头仍在发送。
在对页面进行硬刷新时,授权标头会被完全删除。
当我的用户注销时,如何确保“authInterceptor”注册令牌值的更改?