This repository has been archived on 2025-02-19. You can view files and clone it, but cannot push or open issues or pull requests.
casino/frontend/src/app/auth.guard.ts
Huy c81ad44858 chore(setup): Add and configure prettier (!4)
Co-authored-by: Phan Huy Tran <p.tran@neusta.de>
Reviewed-on: https://git.simonis.lol/projects/casino/pulls/4
Reviewed-by: Hop In, I Have Puppies AND WiFi <jleibl@noreply@simonis.lol>
2025-02-05 10:01:05 +00:00

16 lines
414 B
TypeScript

import { CanActivateFn } from '@angular/router';
import { inject } from '@angular/core';
import { KeycloakService } from 'keycloak-angular';
export const authGuard: CanActivateFn = async (route, state) => {
const keycloakService = inject(KeycloakService);
const isLoggedIn = keycloakService.isLoggedIn();
if (isLoggedIn) {
return true;
} else {
keycloakService.login();
return false;
}
};