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
651 B
TypeScript
23 lines
651 B
TypeScript
import { inject } from '@angular/core';
|
|
import { CanActivateFn, Router } from '@angular/router';
|
|
import { map } from 'rxjs';
|
|
import { AuthService } from './auth.service';
|
|
|
|
/**
|
|
* Sin sesión no hay ruta protegida: se manda al inicio de sesión y se recuerda
|
|
* `returnUrl` para volver a donde iba el usuario.
|
|
*/
|
|
export const authGuard: CanActivateFn = (_ruta, estado) => {
|
|
const auth = inject(AuthService);
|
|
const router = inject(Router);
|
|
return auth
|
|
.sesion()
|
|
.pipe(
|
|
map(
|
|
(usuario) =>
|
|
usuario !== null ||
|
|
router.createUrlTree(['/login'], { queryParams: { returnUrl: estado.url } }),
|
|
),
|
|
);
|
|
};
|