0

私の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への呼び出しに対してヘッダーが送信されます。

私が直面している問題は...ユーザーがAngularアプリでサインアウトすると、Auth.user.tokenを既に削除してもAuthorizationヘッダーがまだ送信されていることです。

ページをハード リフレッシュすると、Authorization ヘッダーが完全に削除されます。

ユーザーがサインアウトするときに「authInterceptor」がトークン値の変更を登録するようにするにはどうすればよいですか?

4

1 に答える 1