17 lines
562 B
TypeScript
17 lines
562 B
TypeScript
import {CanActivateFn, Router} from '@angular/router';
|
|
import {inject} from '@angular/core';
|
|
import {CookieService} from 'ngx-cookie-service';
|
|
import {AuthService} from '../auth.service';
|
|
|
|
export const writerGuard: CanActivateFn = (route, state) => {
|
|
const router = inject(Router);
|
|
const cookieService = inject(CookieService);
|
|
const authService = inject(AuthService);
|
|
|
|
if ((authService.isAuthenticated() && JSON.parse(cookieService.get("author")).role !== 'WRITER') || !authService.isAuthenticated()) {
|
|
router.navigate(['/']);
|
|
}
|
|
|
|
return true;
|
|
};
|