Prompt login dialog when user is unauthenticated during auth guard check.
This commit is contained in:
parent
5a4df2572d
commit
b3999b3389
|
|
@ -1,7 +1,9 @@
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
||||||
import {Observable} from 'rxjs';
|
import {map, Observable} from 'rxjs';
|
||||||
import {AuthService} from '@services/auth.service';
|
import {AuthService} from '@services/auth.service';
|
||||||
|
import {MatDialog} from '@angular/material/dialog';
|
||||||
|
import {LoginDialogComponent} from '@shared-components/login/login.component';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
|
@ -10,7 +12,8 @@ export class AuthGuard implements CanActivate {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private router: Router
|
private router: Router,
|
||||||
|
private dialog: MatDialog
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,7 +22,16 @@ export class AuthGuard implements CanActivate {
|
||||||
state: RouterStateSnapshot
|
state: RouterStateSnapshot
|
||||||
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||||
if (!this.authService.checkAuthStatus()) {
|
if (!this.authService.checkAuthStatus()) {
|
||||||
return this.router.createUrlTree(['/']);
|
this.router.createUrlTree(['/']);
|
||||||
|
const dialogRef = this.dialog.open(LoginDialogComponent);
|
||||||
|
return dialogRef.afterClosed().pipe(
|
||||||
|
map(result => {
|
||||||
|
if (result) {
|
||||||
|
return this.router.createUrlTree([state.url]);
|
||||||
|
}
|
||||||
|
return this.router.createUrlTree(['/']);
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const requiredAuthorizations = route.data['requiredAuthorizations'] as string[];
|
const requiredAuthorizations = route.data['requiredAuthorizations'] as string[];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user