15 lines
381 B
TypeScript
15 lines
381 B
TypeScript
import {CanActivateFn} from '@angular/router';
|
|
import {inject} from '@angular/core';
|
|
import {KeycloakService} from 'keycloak-angular';
|
|
|
|
export const authGuard: CanActivateFn = async () => {
|
|
const keycloakService = inject(KeycloakService);
|
|
const isLoggedIn = keycloakService.isLoggedIn();
|
|
|
|
if (isLoggedIn) {
|
|
return true;
|
|
}
|
|
|
|
keycloakService.login();
|
|
return false;
|
|
};
|