lbs-gitea/maptology/master This commit looks good
add role guard, fix routing,
23 lines
716 B
TypeScript
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
|
|
}
|
|
}
|
|
}
|