Every protected endpoint in SEAM API requires a valid JSON Web Token (JWT). Tokens are issued when a user logs in, cryptographically signed with the server’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/TheSerchCp/SEAM-API/llms.txt
Use this file to discover all available pages before exploring further.
JWT_SECRET, and carry enough information about the user so that no database round-trip is needed to identify who is making a request.
How tokens are issued
CallingPOST /api/v1/auth/login with valid credentials triggers the auth.service.js login function. After verifying the password with bcrypt, the service builds a payload and signs it:
JWT.secret reads from the JWT_SECRET environment variable, and JWT.expiresIn reads from JWT_EXPIRES_IN (defaults to "1h" when the variable is not set).
The full login response contains the token alongside the expiry string, the user object, sidebar navigation items for the user’s role, and the list of permission URIs the role can access:
Login request example
The req.user payload
Once auth.middleware.js verifies a token, it attaches the decoded payload to req.user. Every downstream middleware and controller can read it directly:
req.user.idUser into the AsyncLocalStorage request context so that Socket.IO progress events can be routed to the correct user room without passing the ID through every function call.
Sending the token in HTTP requests
Include the token in theAuthorization header using the Bearer scheme:
401 Unauthorized error before reaching the controller.
The X-Socket-ID header
SEAM API emits real-time progress events over Socket.IO tied to the specific browser tab that initiated a request. To enable this, clients should include their current socket ID as a custom header on every authenticated HTTP request:
context.middleware.js reads this header at the very start of each request and stores it in AsyncLocalStorage. The socket event helpers then emit operation:progress directly to that socket ID rather than to all sockets belonging to the user.
Socket.IO authentication
Connecting to the Socket.IO server also requires a valid JWT. Pass the token in theauth object of the connection options:
JWT_SECRET used for HTTP requests. On success, socket.user is populated with the decoded payload and the socket is automatically joined to the user’s private room (user:{userId}). If the token is missing or invalid, the connection attempt is rejected.
How token verification works
auth.middleware.js wraps jwt.verify in a try/catch. Any tampered, malformed, or expired token causes jwt.verify to throw, which the middleware converts into a 401 UnauthorizedError:
Token missing
Returns
401 Unauthorized — "Token requerido"Token invalid or expired
Returns
401 Unauthorized — "Token inválido o expirado"