Files
maptology/web/angular/src/app/notAuth.guard.ts
T
ilhangeoksu f5c8cd95f3
lbs-gitea/maptology/master This commit looks good
add admin component,
add role guard,
fix routing,
2017-12-15 11:45:12 +01:00

23 lines
716 B
TypeScript

import { Injectable } from '@angular/core';
import {CanActivate, Router, CanActivateChild} from '@angular/router';
import {AuthService} from "./auth.service";
@Injectable()
export class NotAuthGuard implements CanActivateChild {
constructor(
private authService: AuthService,
private router: Router
) { }
// Function to determine whether user is authorized to view route
canActivateChild() {
// Check if user is logged in
if (this.authService.getLogin()) {
this.router.navigate(['/maptology']); // Return error, route to home
return false; // Return false: user not allowed to view route
} else {
return true; // Return true: user is allowed to view route
}
}
}