feat: Convert login button to hompage button when user is authenticated
This commit is contained in:
parent
9289a72acf
commit
3a2b92b3ff
2 changed files with 15 additions and 3 deletions
|
@ -1 +1,5 @@
|
|||
<button (click)="login()">Einloggen</button>
|
||||
@if (isLoggedIn) {
|
||||
<button routerLink="/home">Zur Homepage</button>
|
||||
} @else {
|
||||
<button (click)="login()">Einloggen</button>
|
||||
}
|
||||
|
|
|
@ -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` });
|
||||
|
|
Reference in a new issue