import {CanActivateFn, Router} from '@angular/router';
import {inject} from '@angular/core';
import {CookieService} from 'ngx-cookie-service';
import {Author} from '../models/author';

export const adminGuard: CanActivateFn = (route, state) => {
  const router = inject(Router);
  const cookieService = inject(CookieService);

  if (cookieService.get("author") !== '') {
    if (JSON.parse(cookieService.get("author")).role !== 'ADMIN')
    {
      router.navigate(['/']);
    }
  }

  return true;
};
