Spaces:
Running
Running
File size: 583 Bytes
a828e09 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import { Injectable } from '@angular/core';
import { CanActivate, Router, UrlTree } from '@angular/router';
import { AuthService } from './auth.service';
import { AuthUiService } from './auth-ui.service';
@Injectable({ providedIn: 'root' })
export class AuthGuard implements CanActivate {
constructor(private auth: AuthService, private authUi: AuthUiService, private router: Router) {}
canActivate(): boolean | UrlTree {
if (this.auth.isAuthenticated()) return true;
this.authUi.openSignin();
return this.router.parseUrl('/'); // redirect home; modal is open
}
}
|