File tree 1 file changed +20
-1
lines changed
1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,11 @@ export class AuthService {
28
28
this . isDoneLoading$
29
29
) . pipe ( map ( values => values . every ( b => b ) ) ) ;
30
30
31
+ private navigateToLoginPage ( ) {
32
+ // TODO: Remember current URL
33
+ this . router . navigateByUrl ( '/should-login' ) ;
34
+ }
35
+
31
36
constructor (
32
37
private oauthService : OAuthService ,
33
38
private router : Router ,
@@ -41,6 +46,20 @@ export class AuthService {
41
46
}
42
47
} ) ;
43
48
49
+ window . addEventListener ( 'storage' , ( event ) => {
50
+ // The `key` is `null` if the event was caused by `.clear()`
51
+ if ( event . key !== 'access_token' && event . key !== null ) {
52
+ return ;
53
+ }
54
+
55
+ console . warn ( 'Noticed changes to access_token (possibly from another tab), updating isAuthenticated' ) ;
56
+ this . isAuthenticatedSubject$ . next ( this . oauthService . hasValidAccessToken ( ) ) ;
57
+
58
+ if ( ! this . oauthService . hasValidAccessToken ( ) ) {
59
+ this . navigateToLoginPage ( ) ;
60
+ }
61
+ } ) ;
62
+
44
63
this . oauthService . events
45
64
. subscribe ( _ => {
46
65
this . isAuthenticatedSubject$ . next ( this . oauthService . hasValidAccessToken ( ) ) ;
@@ -52,7 +71,7 @@ export class AuthService {
52
71
53
72
this . oauthService . events
54
73
. pipe ( filter ( e => [ 'session_terminated' , 'session_error' ] . includes ( e . type ) ) )
55
- . subscribe ( e => this . router . navigateByUrl ( '/should-login' ) ) ; // TODO: Remember current URL
74
+ . subscribe ( e => this . navigateToLoginPage ( ) ) ;
56
75
57
76
this . oauthService . setupAutomaticSilentRefresh ( ) ;
58
77
}
You can’t perform that action at this time.
0 commit comments