52 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { CommonModule } from '@angular/common';
 | |
| import {
 | |
|   ChangeDetectionStrategy,
 | |
|   Component,
 | |
|   computed,
 | |
|   inject,
 | |
| } from '@angular/core';
 | |
| import { Router, RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
 | |
| 
 | |
| import { AuthorityAuthService } from './core/auth/authority-auth.service';
 | |
| import { AuthSessionStore } from './core/auth/auth-session.store';
 | |
| 
 | |
| @Component({
 | |
|   selector: 'app-root',
 | |
|   standalone: true,
 | |
|   imports: [CommonModule, RouterOutlet, RouterLink, RouterLinkActive],
 | |
|   templateUrl: './app.component.html',
 | |
|   styleUrl: './app.component.scss',
 | |
|   changeDetection: ChangeDetectionStrategy.OnPush,
 | |
| })
 | |
| export class AppComponent {
 | |
|   private readonly router = inject(Router);
 | |
|   private readonly auth = inject(AuthorityAuthService);
 | |
|   private readonly sessionStore = inject(AuthSessionStore);
 | |
| 
 | |
|   readonly status = this.sessionStore.status;
 | |
|   readonly identity = this.sessionStore.identity;
 | |
|   readonly subjectHint = this.sessionStore.subjectHint;
 | |
|   readonly isAuthenticated = this.sessionStore.isAuthenticated;
 | |
| 
 | |
|   readonly displayName = computed(() => {
 | |
|     const identity = this.identity();
 | |
|     if (identity?.name) {
 | |
|       return identity.name;
 | |
|     }
 | |
|     if (identity?.email) {
 | |
|       return identity.email;
 | |
|     }
 | |
|     const hint = this.subjectHint();
 | |
|     return hint ?? 'anonymous';
 | |
|   });
 | |
| 
 | |
|   onSignIn(): void {
 | |
|     const returnUrl = this.router.url === '/' ? undefined : this.router.url;
 | |
|     void this.auth.beginLogin(returnUrl);
 | |
|   }
 | |
| 
 | |
|   onSignOut(): void {
 | |
|     void this.auth.logout();
 | |
|   }
 | |
| }
 |