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 { Component, inject } from '@angular/core';
 | 
				
			||||||
import { KeycloakService } from 'keycloak-angular';
 | 
					import { KeycloakService } from 'keycloak-angular';
 | 
				
			||||||
 | 
					import {RouterLink} from "@angular/router";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component({
 | 
					@Component({
 | 
				
			||||||
  selector: 'app-landing-page',
 | 
					  selector: 'app-landing-page',
 | 
				
			||||||
  standalone: true,
 | 
					  standalone: true,
 | 
				
			||||||
  imports: [],
 | 
					  imports: [
 | 
				
			||||||
 | 
					    RouterLink
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
  templateUrl: './landing-page.component.html',
 | 
					  templateUrl: './landing-page.component.html',
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
export class LandingPageComponent {
 | 
					export class LandingPageComponent {
 | 
				
			||||||
 | 
					  public isLoggedIn = false;
 | 
				
			||||||
  private keycloakService: KeycloakService = inject(KeycloakService);
 | 
					  private keycloakService: KeycloakService = inject(KeycloakService);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  login() {
 | 
					  private ngOnInit() {
 | 
				
			||||||
 | 
					    this.isLoggedIn = this.keycloakService.isLoggedIn();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public login() {
 | 
				
			||||||
    const baseUrl = window.location.origin;
 | 
					    const baseUrl = window.location.origin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.keycloakService.login({ redirectUri: `${baseUrl}/home` });
 | 
					    this.keycloakService.login({ redirectUri: `${baseUrl}/home` });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue