feat: Convert login button to hompage button when user is authenticated

This commit is contained in:
Phan Huy Tran 2025-02-12 12:19:31 +01:00
parent 9289a72acf
commit 3a2b92b3ff
2 changed files with 15 additions and 3 deletions

View file

@ -1 +1,5 @@
<button (click)="login()">Einloggen</button>
@if (isLoggedIn) {
<button routerLink="/home">Zur Homepage</button>
} @else {
<button (click)="login()">Einloggen</button>
}

View file

@ -1,16 +1,24 @@
import { Component, inject } from '@angular/core';
import { KeycloakService } from 'keycloak-angular';
import {RouterLink} from "@angular/router";
@Component({
selector: 'app-landing-page',
standalone: true,
imports: [],
imports: [
RouterLink
],
templateUrl: './landing-page.component.html',
})
export class LandingPageComponent {
public isLoggedIn = false;
private keycloakService: KeycloakService = inject(KeycloakService);
login() {
private ngOnInit() {
this.isLoggedIn = this.keycloakService.isLoggedIn();
}
public login() {
const baseUrl = window.location.origin;
this.keycloakService.login({ redirectUri: `${baseUrl}/home` });