Skip to main content
ICP System authenticates users with JSON Web Tokens (JWT). You POST your credentials to the login endpoint, receive an access_token, and that token is automatically attached to every subsequent API request as a Bearer header.

Login flow

To log in, send a POST request to /v1/auth/login with a JSON body containing your username and password.
On success, the frontend saves the returned access_token to localStorage under the key access_token and redirects you to the home page (/).

Token storage and request headers

The token is persisted in localStorage using the key access_token. A request interceptor reads it before every outgoing request and injects it as an Authorization header:
You do not need to manage headers manually — every call made through the shared http Axios instance includes the token automatically.
The access token is stored in localStorage, not in an httpOnly cookie. This means it is accessible to JavaScript running on the page. Ensure your deployment uses HTTPS and apply appropriate Content Security Policy headers to reduce exposure to XSS attacks.

Session expiry and auto-logout

A response interceptor watches every API response for a 401 Unauthorized status. When a 401 is received — for example because the token has expired or been invalidated — the interceptor:
  1. Removes the token from localStorage (clearAccessToken())
  2. Redirects the browser to /login via window.location.href
Any in-flight navigation or unsaved form data will be lost when this redirect fires. Users are returned to the login page where they can authenticate again.

Protected routes

All routes except /login are wrapped in RequireAuth. This component checks for the presence of access_token in localStorage before rendering any protected content. If no token is found, the user is redirected to /login and the originally requested path is preserved in router state so the app can redirect back after a successful login.

Current user profile

After login, the app calls GET /v1/auth/me to fetch the authenticated user’s profile and role assignments.

Role-based access

ICP System uses three roles. The roles array returned by /v1/auth/me determines what each user can see and do. Roles are checked at runtime using the hasRole helper:
Pass the user’s roles array and one or more allowed role strings. The function returns true if the user holds at least one of the allowed roles.
Role assignment is managed through the backend. See Users & roles for instructions on creating accounts and assigning roles via the Users page (/usuarios).