File tree Expand file tree Collapse file tree 2 files changed +25
-8
lines changed
libs/perun/services/src/lib Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -56,20 +56,23 @@ export class ApiInterceptor implements HttpInterceptor {
56
56
) {
57
57
const config = getDefaultDialogConfig ( ) ;
58
58
config . width = '450px' ;
59
+ config . id = 'SessionExpirationDialog' ;
59
60
60
61
// Skip if the dialog is already open
61
- if ( this . dialogRefSessionExpiration == null ) {
62
+ if ( ! this . dialogRefSessionExpiration ) {
62
63
this . dialogRefSessionExpiration = this . dialog . open (
63
64
SessionExpirationDialogComponent ,
64
65
config
65
66
) ;
66
- this . dialogRefSessionExpiration . afterClosed ( ) . subscribe ( ( ) => {
67
- finalize ( ( ) => ( this . dialogRefSessionExpiration = undefined ) ) ;
68
- sessionStorage . setItem ( 'auth:redirect' , location . pathname ) ;
69
- sessionStorage . setItem ( 'auth:queryParams' , location . search . substring ( 1 ) ) ;
70
- this . dialog . closeAll ( ) ;
71
- this . oauthService . logOut ( true ) ;
72
- this . reauthenticate ( ) ;
67
+ this . dialogRefSessionExpiration . afterClosed ( ) . subscribe ( ( manuallyClosed : boolean ) => {
68
+ finalize ( ( ) => ( this . dialogRefSessionExpiration = null ) ) ;
69
+ // Only for the case when user closed the dialog manually to authenticate
70
+ // it can be automatically closed in other tabs once user refreshes session
71
+ if ( manuallyClosed ) {
72
+ this . dialog . closeAll ( ) ;
73
+ this . oauthService . logOut ( true ) ;
74
+ this . reauthenticate ( ) ;
75
+ }
73
76
} ) ;
74
77
}
75
78
}
Original file line number Diff line number Diff line change @@ -33,8 +33,22 @@ export class AuthService {
33
33
this . filterShortname = String ( params [ 'idpFilter' ] ) ;
34
34
}
35
35
} ) ;
36
+
37
+ // The storage event of the Window interface fires when a storage area (localStorage) has been modified in the context of another document.
38
+ window . addEventListener ( 'storage' , this . closeSessionDialogsForOtherTabs ) ;
36
39
}
37
40
41
+ closeSessionDialogsForOtherTabs = ( event : StorageEvent ) : void => {
42
+ // Check if user authenticated in other tab and if so close the session expiration dialog
43
+ if ( event . key === 'access_token' && this . oauthService . hasValidAccessToken ( ) ) {
44
+ this . dialog . openDialogs . forEach ( ( dialog ) => {
45
+ if ( dialog . id === 'SessionExpirationDialog' ) {
46
+ dialog . close ( ) ;
47
+ }
48
+ } ) ;
49
+ }
50
+ } ;
51
+
38
52
loadOidcConfigData ( ) : void {
39
53
this . oauthService . configure ( this . getClientConfig ( ) ) ;
40
54
}
You can’t perform that action at this time.
0 commit comments