mirror of
https://github.com/zitadel/zitadel.git
synced 2025-02-28 21:27:22 +00:00
fix(console): trigger unauthenticated dialog only once (#1170)
* fix: trigger dialog once * remove log * typed trigger
This commit is contained in:
parent
81b2c6d02c
commit
7f554813b3
@ -1,7 +1,8 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { Request, UnaryInterceptor, UnaryResponse } from 'grpc-web';
|
import { Request, UnaryInterceptor, UnaryResponse } from 'grpc-web';
|
||||||
import { filter, first, take } from 'rxjs/operators';
|
import { Subject } from 'rxjs';
|
||||||
|
import { debounceTime, filter, first, take } from 'rxjs/operators';
|
||||||
import { WarnDialogComponent } from 'src/app/modules/warn-dialog/warn-dialog.component';
|
import { WarnDialogComponent } from 'src/app/modules/warn-dialog/warn-dialog.component';
|
||||||
|
|
||||||
import { AuthenticationService } from '../authentication.service';
|
import { AuthenticationService } from '../authentication.service';
|
||||||
@ -16,11 +17,16 @@ const accessTokenStorageKey = 'access_token';
|
|||||||
* Set the authentication token
|
* Set the authentication token
|
||||||
*/
|
*/
|
||||||
export class AuthInterceptor<TReq = unknown, TResp = unknown> implements UnaryInterceptor<TReq, TResp> {
|
export class AuthInterceptor<TReq = unknown, TResp = unknown> implements UnaryInterceptor<TReq, TResp> {
|
||||||
|
public triggerDialog: Subject<boolean> = new Subject();
|
||||||
constructor(
|
constructor(
|
||||||
private authenticationService: AuthenticationService,
|
private authenticationService: AuthenticationService,
|
||||||
private storageService: StorageService,
|
private storageService: StorageService,
|
||||||
private dialog: MatDialog,
|
private dialog: MatDialog,
|
||||||
) { }
|
) {
|
||||||
|
this.triggerDialog.pipe(debounceTime(1000)).subscribe(() => {
|
||||||
|
this.openDialog();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async intercept(request: Request<TReq, TResp>, invoker: any): Promise<UnaryResponse<TReq, TResp>> {
|
public async intercept(request: Request<TReq, TResp>, invoker: any): Promise<UnaryResponse<TReq, TResp>> {
|
||||||
await this.authenticationService.authenticationChanged.pipe(
|
await this.authenticationService.authenticationChanged.pipe(
|
||||||
@ -36,22 +42,26 @@ export class AuthInterceptor<TReq = unknown, TResp = unknown> implements UnaryIn
|
|||||||
return response;
|
return response;
|
||||||
}).catch((error: any) => {
|
}).catch((error: any) => {
|
||||||
if (error.code === 16) {
|
if (error.code === 16) {
|
||||||
const dialogRef = this.dialog.open(WarnDialogComponent, {
|
this.triggerDialog.next(true);
|
||||||
data: {
|
|
||||||
confirmKey: 'ACTIONS.LOGIN',
|
|
||||||
titleKey: 'ERRORS.TOKENINVALID.TITLE',
|
|
||||||
descriptionKey: 'ERRORS.TOKENINVALID.DESCRIPTION',
|
|
||||||
},
|
|
||||||
width: '400px',
|
|
||||||
});
|
|
||||||
|
|
||||||
dialogRef.afterClosed().pipe(take(1)).subscribe(resp => {
|
|
||||||
if (resp) {
|
|
||||||
this.authenticationService.authenticate(undefined, true, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openDialog() {
|
||||||
|
const dialogRef = this.dialog.open(WarnDialogComponent, {
|
||||||
|
data: {
|
||||||
|
confirmKey: 'ACTIONS.LOGIN',
|
||||||
|
titleKey: 'ERRORS.TOKENINVALID.TITLE',
|
||||||
|
descriptionKey: 'ERRORS.TOKENINVALID.DESCRIPTION',
|
||||||
|
},
|
||||||
|
width: '400px',
|
||||||
|
});
|
||||||
|
|
||||||
|
dialogRef.afterClosed().pipe(take(1)).subscribe(resp => {
|
||||||
|
if (resp) {
|
||||||
|
this.authenticationService.authenticate(undefined, true, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user