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/shared/components/navbar/navbar.component.ts

34 lines
875 B
TypeScript

import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { RouterModule } from '@angular/router';
import { KeycloakService } from 'keycloak-angular';
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
standalone: true,
imports: [RouterModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NavbarComponent {
isMenuOpen = false;
private keycloakService: KeycloakService = inject(KeycloakService);
isLoggedIn = this.keycloakService.isLoggedIn();
login() {
try {
const baseUrl = window.location.origin;
this.keycloakService.login({ redirectUri: `${baseUrl}/login/success` });
} catch (error) {
console.error('Login failed:', error);
}
}
logout() {
this.keycloakService.logout();
}
toggleMenu() {
this.isMenuOpen = !this.isMenuOpen;
}
}