Initial implementation of login and registration with fake backend for future testing
Also introduced flex-layout
This commit is contained in:
21
src/app/account/auth.guard.ts
Normal file
21
src/app/account/auth.guard.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||
import { AccountService } from './account.service';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class AuthGuard implements CanActivate {
|
||||
constructor(private router: Router,
|
||||
private accountService: AccountService) { }
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
||||
const user = this.accountService.userValue;
|
||||
|
||||
if (user) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this.router.navigate(['/login'], {queryParams: {returnURL: state.url}});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user