Refactor HeaderComponent to organize inputs, inject dependencies, and improve HTML formatting. Add logout method for authentication management.
This commit is contained in:
parent
c2b9a8a574
commit
0b952e07f7
|
|
@ -154,14 +154,20 @@
|
|||
Login
|
||||
</a>
|
||||
</li>
|
||||
} @else {
|
||||
<li class="nav_li login-button">
|
||||
<a class="nav_link fake_link" (click)="logout()">
|
||||
Login
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
|
||||
<app-theme></app-theme>
|
||||
</div>
|
||||
</nav>
|
||||
</nav>
|
||||
|
||||
<ng-content select="[header-content]"></ng-content>
|
||||
<ng-content select="[header-content]"></ng-content>
|
||||
|
||||
</header>
|
||||
</header>
|
||||
</ng-container>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {Component, HostListener, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Component, HostListener, inject, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {CommonModule, NgOptimizedImage} from '@angular/common';
|
||||
import {ThemeComponent} from '@shared-components/theme/theme.component';
|
||||
import {RouterLink} from '@angular/router';
|
||||
|
|
@ -20,6 +20,10 @@ import {MatDialog} from '@angular/material/dialog';
|
|||
styleUrls: ['./header.component.scss']
|
||||
})
|
||||
export class HeaderComponent implements OnInit, OnDestroy {
|
||||
|
||||
private authService: AuthService = inject(AuthService)
|
||||
private dialog: MatDialog = inject(MatDialog)
|
||||
|
||||
@Input() current_page: string = '';
|
||||
@Input() background_image: string = '';
|
||||
@Input() height: string = '';
|
||||
|
|
@ -30,11 +34,6 @@ export class HeaderComponent implements OnInit, OnDestroy {
|
|||
private subscription: Subscription | undefined;
|
||||
public isAuthenticated: boolean = false;
|
||||
|
||||
constructor(protected authService: AuthService,
|
||||
private dialog: MatDialog) {
|
||||
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.subscription = this.authService.isAuthenticated$.subscribe(isAuthenticated => {
|
||||
this.isAuthenticated = isAuthenticated;
|
||||
|
|
@ -94,4 +93,8 @@ export class HeaderComponent implements OnInit, OnDestroy {
|
|||
public hasAccess(claims: string[]): boolean {
|
||||
return this.authService.hasAccess(claims)
|
||||
}
|
||||
|
||||
protected logout() {
|
||||
this.authService.logout()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user