feat(navbar): implement login/logout buttons based on state
This commit is contained in:
parent
325bc118ee
commit
e5bd173be9
5 changed files with 57 additions and 16 deletions
|
@ -19,3 +19,4 @@ export class LandingComponent {
|
||||||
this.keycloakService.login({ redirectUri: `${baseUrl}/home` });
|
this.keycloakService.login({ redirectUri: `${baseUrl}/home` });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export class LandingPageComponent {}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<button (click)="login()">Einloggen</button>
|
|
@ -1,5 +1,4 @@
|
||||||
import { Component } from '@angular/core';
|
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||||
import { RouterLink } from '@angular/router';
|
|
||||||
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
||||||
import { faMoneyBillTransfer, faCreditCard, faWallet } from '@fortawesome/free-solid-svg-icons';
|
import { faMoneyBillTransfer, faCreditCard, faWallet } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { faPaypal, faGooglePay, faApplePay } from '@fortawesome/free-brands-svg-icons';
|
import { faPaypal, faGooglePay, faApplePay } from '@fortawesome/free-brands-svg-icons';
|
||||||
|
@ -9,11 +8,11 @@ import { faPaypal, faGooglePay, faApplePay } from '@fortawesome/free-brands-svg-
|
||||||
standalone: true,
|
standalone: true,
|
||||||
templateUrl: './footer.component.html',
|
templateUrl: './footer.component.html',
|
||||||
imports: [FontAwesomeModule],
|
imports: [FontAwesomeModule],
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class FooterComponent {
|
export class FooterComponent {
|
||||||
currentYear: number = new Date().getFullYear();
|
currentYear: number = new Date().getFullYear();
|
||||||
|
|
||||||
// Payment method icons
|
|
||||||
faPaypal = faPaypal;
|
faPaypal = faPaypal;
|
||||||
faCreditCard = faCreditCard;
|
faCreditCard = faCreditCard;
|
||||||
faMoneyBillTransfer = faMoneyBillTransfer;
|
faMoneyBillTransfer = faMoneyBillTransfer;
|
||||||
|
|
|
@ -15,11 +15,22 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="hidden md:flex items-center space-x-4">
|
<div class="hidden md:flex items-center space-x-4">
|
||||||
<button
|
@if (!isLoggedIn) {
|
||||||
class="cursor-pointer px-4 py-1.5 rounded bg-emerald-500 hover:bg-emerald-600 text-white text-sm font-medium transition-colors duration-200"
|
<button
|
||||||
>
|
(click)="login()"
|
||||||
Login
|
class="cursor-pointer px-4 py-1.5 rounded bg-emerald-500 hover:bg-emerald-600 text-white text-sm font-medium transition-colors duration-200"
|
||||||
</button>
|
>
|
||||||
|
Login
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
@if (isLoggedIn) {
|
||||||
|
<button
|
||||||
|
(click)="logout()"
|
||||||
|
class="cursor-pointer px-4 py-1.5 rounded bg-emerald-500 hover:bg-emerald-600 text-white text-sm font-medium transition-colors duration-200"
|
||||||
|
>
|
||||||
|
Logout
|
||||||
|
</button>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="md:hidden">
|
<div class="md:hidden">
|
||||||
|
@ -67,11 +78,22 @@
|
||||||
>Games</a
|
>Games</a
|
||||||
>
|
>
|
||||||
<div class="pt-2 space-y-2">
|
<div class="pt-2 space-y-2">
|
||||||
<button
|
@if (!isLoggedIn) {
|
||||||
class="cursor-pointer w-full px-4 py-1.5 rounded bg-emerald-500 hover:bg-emerald-600 text-white text-sm font-medium transition-colors duration-200"
|
<button
|
||||||
>
|
(click)="login()"
|
||||||
Login
|
class="cursor-pointer w-full px-4 py-1.5 rounded bg-emerald-500 hover:bg-emerald-600 text-white text-sm font-medium transition-colors duration-200"
|
||||||
</button>
|
>
|
||||||
|
Login
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
@if (isLoggedIn) {
|
||||||
|
<button
|
||||||
|
(click)="logout()"
|
||||||
|
class="cursor-pointer w-full px-4 py-1.5 rounded bg-emerald-500 hover:bg-emerald-600 text-white text-sm font-medium transition-colors duration-200"
|
||||||
|
>
|
||||||
|
Logout
|
||||||
|
</button>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,15 +1,33 @@
|
||||||
import { Component } from '@angular/core';
|
import { AsyncPipe } from '@angular/common';
|
||||||
|
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
||||||
import { RouterModule } from '@angular/router';
|
import { RouterModule } from '@angular/router';
|
||||||
import { CommonModule } from '@angular/common';
|
import { KeycloakService } from 'keycloak-angular';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-navbar',
|
selector: 'app-navbar',
|
||||||
templateUrl: './navbar.component.html',
|
templateUrl: './navbar.component.html',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, RouterModule],
|
imports: [RouterModule, AsyncPipe],
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class NavbarComponent {
|
export class NavbarComponent {
|
||||||
isMenuOpen = false;
|
isMenuOpen = false;
|
||||||
|
private keycloakService: KeycloakService = inject(KeycloakService);
|
||||||
|
|
||||||
|
isLoggedIn = this.keycloakService.isLoggedIn();
|
||||||
|
|
||||||
|
login() {
|
||||||
|
try {
|
||||||
|
const baseUrl = window.location.origin;
|
||||||
|
this.keycloakService.login({ redirectUri: `${baseUrl}/home` });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Login failed:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logout() {
|
||||||
|
this.keycloakService.logout();
|
||||||
|
}
|
||||||
|
|
||||||
toggleMenu() {
|
toggleMenu() {
|
||||||
this.isMenuOpen = !this.isMenuOpen;
|
this.isMenuOpen = !this.isMenuOpen;
|
||||||
|
|
Reference in a new issue