From 7f176814096b1c7b0dd1570a3ac8311fe6933a74 Mon Sep 17 00:00:00 2001 From: Erick ivan <72117592+ElVigilanteDelAula@users.noreply.github.com> Date: Thu, 19 Nov 2026 09:36:48 -0600 Subject: [PATCH] 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. --- nginx.conf | 2 +- proxy.conf.json | 1 + src/app/app-encabezado.spec.ts | 3 +- src/app/app.config.ts | 6 +- src/app/app.html | 65 ++++--- src/app/app.routes.ts | 94 ++++++---- src/app/app.scss | 40 +++++ src/app/app.spec.ts | 121 ++++++++++--- src/app/app.ts | 24 ++- src/app/auth/auth.guard.ts | 22 +++ src/app/auth/auth.interceptor.ts | 27 +++ src/app/auth/auth.service.spec.ts | 70 ++++++++ src/app/auth/auth.service.ts | 76 ++++++++ src/app/auth/dominio.guard.ts | 22 +++ src/app/auth/dominios.ts | 27 +++ src/app/auth/login-page.html | 59 ++++++ src/app/auth/login-page.scss | 170 ++++++++++++++++++ src/app/auth/login-page.ts | 61 +++++++ .../components/connect-page/connect-page.html | 2 +- .../components/connect-page/connect-page.ts | 8 +- .../state/connect-workspace.store.spec.ts | 22 +++ .../connect/state/connect-workspace.store.ts | 13 +- .../experiments-panel/experiments-panel.html | 2 +- .../experiments-panel/experiments-panel.ts | 14 +- .../model-versions-panel.html | 2 +- .../model-versions-panel.ts | 14 +- src/app/home.html | 6 +- src/app/home.scss | 20 +-- src/styles.scss | 4 + 29 files changed, 876 insertions(+), 121 deletions(-) create mode 100644 src/app/auth/auth.guard.ts create mode 100644 src/app/auth/auth.interceptor.ts create mode 100644 src/app/auth/auth.service.spec.ts create mode 100644 src/app/auth/auth.service.ts create mode 100644 src/app/auth/dominio.guard.ts create mode 100644 src/app/auth/dominios.ts create mode 100644 src/app/auth/login-page.html create mode 100644 src/app/auth/login-page.scss create mode 100644 src/app/auth/login-page.ts diff --git a/nginx.conf b/nginx.conf index 4c46b13..f7d5319 100644 --- a/nginx.conf +++ b/nginx.conf @@ -12,7 +12,7 @@ server { gzip_types text/css application/javascript application/json image/svg+xml; gzip_min_length 1024; - location ~ ^/(api|imports|data|cacu|cama|tea|governance|reportes|health)(/|$) { + location ~ ^/(api|auth|imports|data|cacu|cama|tea|governance|reportes|health)(/|$) { proxy_pass http://webapi:5000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/proxy.conf.json b/proxy.conf.json index 9890b3c..243b14e 100644 --- a/proxy.conf.json +++ b/proxy.conf.json @@ -1,5 +1,6 @@ { "/api": { "target": "http://localhost:5050", "secure": false, "changeOrigin": true }, + "/auth": { "target": "http://localhost:5050", "secure": false, "changeOrigin": true }, "/imports": { "target": "http://localhost:5050", "secure": false, "changeOrigin": true }, "/data": { "target": "http://localhost:5050", "secure": false, "changeOrigin": true }, "/health": { "target": "http://localhost:5050", "secure": false, "changeOrigin": true }, diff --git a/src/app/app-encabezado.spec.ts b/src/app/app-encabezado.spec.ts index 24ab7a6..2d3d2b8 100644 --- a/src/app/app-encabezado.spec.ts +++ b/src/app/app-encabezado.spec.ts @@ -37,7 +37,8 @@ describe('Encabezado del marco', () => { it('las rutas de los tres dominios existen en el enrutador de la aplicación', () => { // Fails if the selector would point at a route the application does not have. - const paths = routes.map(r => r.path); + // The application's routes live under the guarded parent ('login' is its sibling). + const paths = routes.flatMap((ruta) => [ruta.path, ...(ruta.children ?? []).map((hijo) => hijo.path)]); for (const dominio of DOMINIOS) expect(paths).toContain(`indicadores/${dominio}`); }); it.each([['tea', 'TEA'], ['cacu', 'CaCu'], ['cama', 'Cáncer de mama']] as const)('en /indicadores/%s muestra el título de la plataforma y el selector con «%s»', async (dominio, etiqueta) => { diff --git a/src/app/app.config.ts b/src/app/app.config.ts index a8b7623..69f1168 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -1,7 +1,8 @@ import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core'; -import { provideHttpClient } from '@angular/common/http'; +import { provideHttpClient, withInterceptors } from '@angular/common/http'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; +import { authInterceptor } from './auth/auth.interceptor'; import { IndicadoresService } from './features/indicadores/indicadores.service'; import { IndicadoresPeriodos } from './features/indicadores/indicadores-periodos'; import { TeaSeguimientoService } from './features/indicadores/tea-seguimiento.service'; @@ -12,7 +13,8 @@ export const appConfig: ApplicationConfig = { providers: [ provideBrowserGlobalErrorListeners(), provideRouter(routes), - provideHttpClient(), + // `authInterceptor` regresa al inicio de sesión cuando el servidor responde 401. + provideHttpClient(withInterceptors([authInterceptor])), // The indicator page reads the WebApi's FHIR endpoint; without these lines it reads the indicator JSON contract // (`//indicadores//datos`, `/tea/seguimiento`). { provide: IndicadoresService, useClass: FhirIndicadoresService }, diff --git a/src/app/app.html b/src/app/app.html index 7312335..b4ff016 100644 --- a/src/app/app.html +++ b/src/app/app.html @@ -1,33 +1,52 @@
- + } @else { + + } + @if (usuario(); as sesion) { + + } +
+ + }
- @if (!workspace()) { + @if (!workspace() && !sinCromo()) {