feat(auth): login screen and domain-scoped navigation
Session login against /auth/*, with a guard on every route and an interceptor that returns to the login on 401. The header, the import workspace and both governance panels only offer the account's own domains (auth/dominios.ts), and a batch opens on the account's database. The sign-in screen follows the app's palette: logo above the title, the action button in the shared tokens, and no register or password-recovery rows.
This commit is contained in:
+22
-2
@@ -1,12 +1,14 @@
|
||||
import { Component, computed, inject } from '@angular/core';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterOutlet } from '@angular/router';
|
||||
import { filter, map } from 'rxjs';
|
||||
import { AuthService } from './auth/auth.service';
|
||||
import { DomainSelector } from './domain-selector';
|
||||
import { Dominio, DOMINIOS } from './features/indicadores/indicadores.models';
|
||||
|
||||
@Component({
|
||||
imports: [RouterLink, RouterOutlet, DomainSelector],
|
||||
imports: [MatIconModule, RouterLink, RouterOutlet, DomainSelector],
|
||||
selector: 'app-root',
|
||||
styleUrl: './app.scss',
|
||||
templateUrl: './app.html',
|
||||
@@ -14,6 +16,7 @@ import { Dominio, DOMINIOS } from './features/indicadores/indicadores.models';
|
||||
export class App {
|
||||
private readonly router = inject(Router);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly auth = inject(AuthService);
|
||||
|
||||
private readonly leafRouteData = toSignal(
|
||||
this.router.events.pipe(
|
||||
@@ -30,7 +33,10 @@ export class App {
|
||||
/** Full-height workspace routes (`data.workspace`) drop the marketing footer. */
|
||||
readonly workspace = computed(() => !!this.leafRouteData()['workspace']);
|
||||
readonly breadcrumb = computed(() => this.leafRouteData()['breadcrumb'] as string | undefined);
|
||||
/** The login screen (`data.sinCromo`) owns the whole window: no header, no footer. */
|
||||
readonly sinCromo = computed(() => !!this.leafRouteData()['sinCromo']);
|
||||
|
||||
protected readonly usuario = this.auth.usuario;
|
||||
protected readonly title = 'Plataforma de Indicadores';
|
||||
protected readonly domainLabels: Record<Dominio, string> = { tea: 'TEA', cacu: 'CaCu', cama: 'Cáncer de mama' };
|
||||
private readonly url = toSignal(this.router.events.pipe(
|
||||
@@ -38,5 +44,19 @@ export class App {
|
||||
/** On an indicators page the header names its domain and switches to the others. */
|
||||
protected readonly activeDomain = computed(() =>
|
||||
DOMINIOS.find(domain => new RegExp(`^/indicadores/${domain}(?:[/?#]|$)`).test(this.url())));
|
||||
protected readonly otherDomains = computed(() => DOMINIOS.filter(domain => domain !== this.activeDomain()));
|
||||
/** Only the domains the account may see: the header never offers a forbidden one. */
|
||||
private readonly permitidos = computed<readonly Dominio[]>(() => {
|
||||
const sesion = this.auth.usuario();
|
||||
return sesion ? DOMINIOS.filter(dominio => sesion.dominios.includes(dominio)) : DOMINIOS;
|
||||
});
|
||||
protected readonly otherDomains = computed(() =>
|
||||
this.permitidos().filter(domain => domain !== this.activeDomain()));
|
||||
|
||||
protected salir(): void {
|
||||
// Whether the server session was already gone, the browser ends up at the login screen.
|
||||
this.auth.logout().subscribe({
|
||||
next: () => void this.router.navigate(['/login']),
|
||||
error: () => void this.router.navigate(['/login']),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user