import { inject } from '@angular/core';
import { ResolveFn } from '@angular/router';
import { KeycloakService } from '../services/keycloak.service';

export const authResolver: ResolveFn<boolean> = async (route, state) => {
  const keycloakService: KeycloakService = inject(KeycloakService);

  if (!keycloakService.isLoggedIn()) {
    await keycloakService.login({
      redirectUri: window.location.href,
    });
  }

  return true;
};
