mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-07 14:52:15 +00:00
* managementservice, authservice, change all refs * refactor grpc auth * fix references * interceptor logic * new interceptor * appinitializers, environment loader, interceptors * remove circular dep * init authconfig in grpc service * authconfig * lint * update mgmt service * fix references * update clientid, fix interceptor * rm unused authconfig * todo auth interceptor
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { Observable } from 'rxjs';
|
|
import { take } from 'rxjs/operators';
|
|
|
|
import { WarnDialogComponent } from '../modules/warn-dialog/warn-dialog.component';
|
|
import { AuthenticationService } from './authentication.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class ToastService {
|
|
constructor(private dialog: MatDialog,
|
|
private snackBar: MatSnackBar,
|
|
private translate: TranslateService,
|
|
private authService: AuthenticationService,
|
|
) { }
|
|
|
|
public showInfo(message: string, i18nkey: boolean = false): void {
|
|
if (i18nkey) {
|
|
this.translate
|
|
.get(message)
|
|
.subscribe(data => {
|
|
this.showMessage(data, 'close');
|
|
});
|
|
} else {
|
|
this.showMessage(message, 'close');
|
|
}
|
|
}
|
|
|
|
public showError(grpcError: any): void {
|
|
const { message, code, metadata } = grpcError;
|
|
// TODO: remove check for code === 7
|
|
if (code === 16 || (code === 7 && message === 'invalid token')) {
|
|
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.authService.authenticate(undefined, true, true);
|
|
}
|
|
});
|
|
} else {
|
|
this.showMessage(decodeURI(message), 'close', { duration: 3000 });
|
|
}
|
|
}
|
|
|
|
private showMessage(message: string, action: string, config?: MatSnackBarConfig): Observable<void> {
|
|
const ref = this.snackBar.open(message, action, config);
|
|
|
|
return ref.onAction();
|
|
}
|
|
}
|