Back to path after login
This commit is contained in:
@@ -7,14 +7,20 @@ import { AuthService } from './auth.service';
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AuthGuard {
|
export class AuthGuard {
|
||||||
|
loginUrl: string | null = null;
|
||||||
constructor(
|
constructor(
|
||||||
private auth$: AuthService,
|
private auth$: AuthService,
|
||||||
private router$: Router
|
private router$: Router,
|
||||||
) {}
|
) {}
|
||||||
canActivate(): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
canActivate(): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||||
if (this.auth$.user && this.auth$.user.googleCredentials) {
|
if (this.auth$.user && this.auth$.user.googleCredentials) {
|
||||||
|
if (this.loginUrl) {
|
||||||
|
this.router$.navigate([this.loginUrl]);
|
||||||
|
this.loginUrl = null;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
this.loginUrl = window.location.pathname;
|
||||||
this.router$.navigate(['']);
|
this.router$.navigate(['']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user