Aibar SRL App authenticates users against a FastAPI backend using the OAuth2 password flow. When a user submits their credentials,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/lucavallini/aibar-frontend/llms.txt
Use this file to discover all available pages before exploring further.
AuthService.login() sends an application/x-www-form-urlencoded POST request to /auth/login. The backend responds with a signed JWT access token, which the Angular client stores in sessionStorage. From that point on, every outgoing HTTP request is automatically stamped with an Authorization: Bearer <token> header by a functional interceptor — no component-level wiring required. A reactive Angular signal keeps the rest of the application instantly aware of the session state without any polling or manual subscriptions.
Data models
TheLoginResponse interface describes the exact shape returned by the /auth/login endpoint, and the Usuario interface represents a full user record as returned by the users API:
Login flow
User submits credentials
The
LoginComponent binds the username and password inputs via Angular’s NgModel two-way binding. On form submission, onSubmit() delegates to AuthService.login() and manages the loading/error signals.AuthService sends the OAuth2 password request
AuthService.login() encodes the credentials as application/x-www-form-urlencoded — the format required by FastAPI’s OAuth2 password endpoint — and POSTs to ${apiUrl}/auth/login. The tap() operator stores the token and flips the reactive signal before the observable reaches any subscriber.Token stored and session signal updated
Inside the
tap() callback, the raw JWT string is persisted to sessionStorage under the key aibar_token, and the isLoggedIn signal is set to true. Any component that reads authService.isLoggedIn() automatically re-renders without needing an explicit change-detection trigger.Token storage
The JWT is stored insessionStorage using the private key 'aibar_token'. Storage reads and writes are encapsulated inside AuthService — no other class touches sessionStorage directly.
Reactive login state
isLoggedIn is an Angular signal<boolean> initialized from hayToken() at service construction time. This means the session state survives in-app navigation (Angular’s router does not tear down the service), but is correctly false in a fresh tab even if a prior session existed in another tab.
authService.isLoggedIn() — and Angular’s reactivity system automatically propagates changes to any template or computed that depends on it.
Token payload decoding
getPayload() extracts the JWT’s claims by splitting on ., base64-decoding the middle segment, and parsing the resulting JSON. It returns a typed object containing the username (sub) and the user’s role (rol), or null if no token exists or decoding fails.
getPayload() performs no signature verification — that is the backend’s responsibility. The decoded payload is used purely for reading claims (role, subject) on the client side to drive UI decisions such as guard checks and sidebar visibility.Logout
Callinglogout() removes the token from sessionStorage, resets the isLoggedIn signal to false, and navigates the user back to /login. All three steps happen synchronously.
Login form template
The login form uses Angular’s template-driven forms withNgModel. The submit button is disabled while the request is in flight, and error messages are rendered conditionally using Angular’s @if control flow syntax.
HTTP interceptor
TheauthInterceptor is a functional HttpInterceptorFn registered in the application’s provider configuration. It intercepts every outgoing request, checks sessionStorage for aibar_token, and — if a token is present — clones the request with the Authorization: Bearer <token> header before passing it along. Requests made when no token exists (e.g., the login call itself) are forwarded unmodified.