TuKit uses JSON Web Tokens (JWT) — signed with a configurableDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/tukit/llms.txt
Use this file to discover all available pages before exploring further.
SECRET from the server’s config — as the primary mechanism for authorising requests to protected endpoints. Tokens are valid for 365 days (expiresIn: "365d") and carry five claims taken directly from the User document at login time: id, userName, email, roles, and activate. The JWT is stored on the User record in MongoDB after each successful login, so the most recently issued token is always persisted server-side.
Registration
New users register by sending aPOST request to /api/user/register with a JSON body containing userName, email, and password. The API hashes the password with bcrypt, creates the User document, and then generates a random 5-digit numeric code that is stored in login_code and dispatched to the user’s email via Nodemailer (Gmail transport).
200)
roles:[{ "name": "Usuario", "value": "1" }]activate:[{ "name": "Inactivo", "value": "2" }]
Account Verification
Once the user has received the 5-digit code by email, they must submit it to activate their account:email and compares the submitted code against the stored login_code. If they match, it:
- Copies the code into
login_code_confirmed. - Updates
activateto[{ "name": "Activado", "value": "1" }].
200)
203) — wrong or missing code:
Login
With the account active, the client can exchange credentials for a JWT:- The user exists.
login_code_confirmedis set (i.e. verification was completed).- The
activatearray contains{ "name": "Activado", "value": "1" }. - The submitted password matches the bcrypt hash.
200)
token value from the response — you will need it for every subsequent authenticated request.
Using the Token
Pass the JWT in thetoken-access request header on every call to a protected endpoint:
Password Recovery
Forgotten passwords are reset through a two-step code-verification flow. Both steps require a valid JWT passed in thetoken-access header — the Token middleware guards both routes.
Step 1 — Request a recovery code
code_newpass, and emails it to the user. The response confirms dispatch:
:email with the user’s URL-encoded email address. The API verifies that code_confirm_pass matches the stored code_newpass. On success, the password is hashed and saved, and both code fields are cleared.
updatePasswordNoCode) does not use the Token middleware and is marked incomplete in the source (//* Sin terminar). It is not yet production-ready and its request/response contract may change.
Token Middleware
Every route that requires authentication is guarded by theToken middleware located at src/middleware/tools/Token.js. Here is what it does, step by step:
- Reads the value of the
token-accessheader from the incoming request. - Returns
403 Sin tokenif the header is absent. - Verifies the JWT signature against
config.SECRETusingjsonwebtoken. - Returns
401 Token inexistenteif verification throws (expired, tampered, or malformed token). - Looks up the user in MongoDB by the
idclaim decoded from the token. - Returns
404 Sin usuarioif no matching document is found. - Attaches the full Mongoose User document to
req.userand callsnext().
req.user, so they always work with up-to-date data regardless of what was encoded in the token at sign time.