mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-04 01:48:50 +00:00
fix(console): toast login handler, show user session loginname, policy value incrementation, accessibility (#413)
* get auth policy, fix increment from 0 * seo, accessibility * ngsw rem check for update * organize interceptors * toast i18n part1 * show loginname * use primary color * toast login handler, fix user session type * Update console/src/assets/i18n/de.json Co-authored-by: Florian Forster <[email protected]> * Update console/src/assets/i18n/de.json Co-authored-by: Florian Forster <[email protected]> * Update console/src/assets/i18n/de.json Co-authored-by: Florian Forster <[email protected]> * Update console/src/assets/i18n/en.json Co-authored-by: Florian Forster <[email protected]> * Update console/src/index.html Co-authored-by: Florian Forster <[email protected]> * Update console/src/assets/i18n/en.json Co-authored-by: Florian Forster <[email protected]> * Update console/src/assets/i18n/en.json Co-authored-by: Florian Forster <[email protected]> Co-authored-by: Florian Forster <[email protected]>
This commit is contained in:
co-authored by
Florian Forster
parent
fa57cc48c1
commit
0721acf605
@@ -1,23 +1,46 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { take } from 'rxjs/operators';
|
||||
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ToastService {
|
||||
constructor(private snackBar: MatSnackBar) { }
|
||||
constructor(private snackBar: MatSnackBar, private translate: TranslateService, private authService: AuthService) { }
|
||||
|
||||
public showInfo(message: string): void {
|
||||
this.showMessage(message, 'close');
|
||||
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(message: string): void {
|
||||
this.showMessage(decodeURI(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 actionObserver$ = this.showMessage(decodeURI(message), 'Login');
|
||||
|
||||
actionObserver$.pipe(take(1)).subscribe(() => {
|
||||
this.authService.authenticate(undefined, true, true);
|
||||
});
|
||||
} else {
|
||||
const actionObserver$ = this.showMessage(decodeURI(message), 'close', { duration: 5000 });
|
||||
}
|
||||
}
|
||||
|
||||
private showMessage(message: string, action: string): void {
|
||||
this.snackBar.open(message, action, {
|
||||
duration: 5000,
|
||||
});
|
||||
private showMessage(message: string, action: string, config?: MatSnackBarConfig): Observable<void> {
|
||||
const ref = this.snackBar.open(message, action, config);
|
||||
|
||||
return ref.onAction();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user