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.
23 lines
850 B
TypeScript
23 lines
850 B
TypeScript
import { inject } from '@angular/core';
|
|
import { CanActivateFn, Router } from '@angular/router';
|
|
import { map } from 'rxjs';
|
|
import { AuthService } from './auth.service';
|
|
|
|
/**
|
|
* Cada cuenta ve solo sus dominios: una ruta con `data.dominio` ajeno manda a la
|
|
* cuenta a su primer dominio. Sin sesión no decide nada (`authGuard` ya la
|
|
* mandó al inicio de sesión).
|
|
*/
|
|
export const dominioGuard: CanActivateFn = (ruta) => {
|
|
const auth = inject(AuthService);
|
|
const router = inject(Router);
|
|
const pedido = ruta.data?.['dominio'] as string | undefined;
|
|
return auth.sesion().pipe(
|
|
map((usuario) => {
|
|
if (!usuario || !pedido || usuario.dominios.includes(pedido)) return true;
|
|
const propio = usuario.dominios[0];
|
|
return propio ? router.createUrlTree(['/indicadores', propio]) : router.createUrlTree(['/']);
|
|
}),
|
|
);
|
|
};
|