Move to new server
This commit is contained in:
23
src/app/authentication/authguard.ts
Normal file
23
src/app/authentication/authguard.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import {Injectable} from "@angular/core";
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from "@angular/router";
|
||||
import {UserService} from "./user.service";
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate {
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
if (this.userService.getUser()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this.router.navigate(['/auth/login'], {
|
||||
queryParams: { returnUrl: state.url },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user