import {CanActivateFn, Router} from '@angular/router';
import {inject} from "@angular/core";
import {AccountService} from "@app/_services";
import {Role} from "@app/_helpers/role";

export const userGuard: CanActivateFn = (route, state) => {
    const accountService = inject(AccountService);
    if (accountService.isLoggedIn() && accountService.userHasRole(Role.ROLE_USER)) {
        return true;
    }
    inject(Router).navigate(['/account/login'], { queryParams: { returnUrl: state.url }});
    return false;
};
