Back to path after login

This commit is contained in:
Michał Zieliński
2023-11-07 00:05:53 +01:00
parent 1142177f15
commit 550854ae95

View File

@@ -7,14 +7,20 @@ import { AuthService } from './auth.service';
providedIn: 'root'
})
export class AuthGuard {
loginUrl: string | null = null;
constructor(
private auth$: AuthService,
private router$: Router
private router$: Router,
) {}
canActivate(): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if (this.auth$.user && this.auth$.user.googleCredentials) {
if (this.loginUrl) {
this.router$.navigate([this.loginUrl]);
this.loginUrl = null;
}
return true;
} else {
this.loginUrl = window.location.pathname;
this.router$.navigate(['']);
return false;
}