7f17681409
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.
28 lines
1.2 KiB
TypeScript
28 lines
1.2 KiB
TypeScript
import { AuthService } from './auth.service';
|
|
|
|
/**
|
|
* Helpers for the screens that list domains (cargar información, gobernanza):
|
|
* an account only ever sees its own, and «Todos» only belongs to one that
|
|
* reaches every domain — the administrator.
|
|
*/
|
|
|
|
/** De la lista dada, las entradas cuyo dominio alcanza la cuenta. */
|
|
export function dominiosPermitidos<T extends { id: string }>(auth: AuthService, dominios: readonly T[]): T[] {
|
|
return dominios.filter((dominio) => auth.puedeVer(dominio.id));
|
|
}
|
|
|
|
/** Si la cuenta alcanza todos: solo entonces tiene sentido ofrecer «Todos». */
|
|
export function alcanzaTodos(auth: AuthService, dominios: readonly { id: string }[]): boolean {
|
|
return dominios.every((dominio) => auth.puedeVer(dominio.id));
|
|
}
|
|
|
|
/**
|
|
* El dominio con el que abre una pantalla: el único que alcanza la cuenta, o
|
|
* `null` («Todos») cuando alcanza varios. Sin sesión resuelta devuelve `null`,
|
|
* que es el comportamiento de siempre.
|
|
*/
|
|
export function dominioInicial<T extends string>(auth: AuthService, dominios: readonly { id: T }[]): T | null {
|
|
const propios = dominiosPermitidos(auth, dominios);
|
|
return propios.length === 1 ? propios[0].id : null;
|
|
}
|