Overview
The API uses JWT (JSON Web Token) authentication powered by djangorestframework-simplejwt. All protected endpoints require a valid access token passed in theAuthorization header.
The frontend stores the access token in a cookie (accessToken) and silently refreshes it every 4 minutes using the refresh token (refreshToken). Access tokens expire after 1 day; refresh tokens expire after 7 days.
How to authenticate requests
Include theAuthorization header with every request to a protected endpoint:
Access levels
| Level | Permission class | Description |
|---|---|---|
| Public | AllowAny | No authentication required |
| Authenticated | IsAuthenticated | Valid access token required |
| Role-restricted | IsAuthenticatedAndRole | Authenticated + member of a specific Django group |
The
IsAuthenticatedAndRole permission class checks request.user.groups. Set required_role on the view to restrict access to a named group. If required_role is not set, authentication alone is sufficient.POST /api/auth/token/
Obtain a JWT access and refresh token pair. This is the primary login endpoint used by the frontend. Accepts username or email in theusername field.
The frontend sends credentials to
/api/auth/token/ (not /api/auth/login/) to receive JWT tokens. The /api/auth/login/ endpoint performs a Django session login and returns user data without issuing JWT tokens.Request body
The user’s username. The custom token serializer looks up the user by exact username match.
The user’s password.
Response
Short-lived JWT access token. Valid for 1 day. Contains
username and email claims in addition to standard JWT fields.Long-lived JWT refresh token. Valid for 7 days. Use this to obtain a new access token without re-entering credentials.
POST /api/auth/token/refresh/
Exchange a valid refresh token for a new access token. The frontend calls this endpoint automatically every 4 minutes to keep sessions alive.Request body
A valid, unexpired refresh token obtained from
/api/auth/token/.Response
A new JWT access token.
POST /api/auth/login/
Authenticates a user via Django session login and returns structured user data. Supports login with either username or email in theusername field.
This endpoint does not issue JWT tokens. For JWT-based auth (the default frontend flow), use
POST /api/auth/token/ instead. Use this endpoint when you need the full user object (groups, flags) without a separate profile fetch.Request body
The user’s username or email address. The serializer searches by username first, then by
User.email, then by UserProfile.email.The user’s password.
Response
"Login exitoso" on success.POST /api/auth/register/
Creates a new user account with an optional extended profile. Acceptsmultipart/form-data to support profile picture uploads.
The role field (roles) is sent at the root level — not nested under profile. The frontend defaults new registrations to the client role.
Request body
Unique username for the new account.
Email address for the account.
Password for the account.
User’s given name.
User’s family name.
List of Django group IDs to assign to the user. Defaults to
client role if omitted.Contact phone number (max 20 characters).
Street address (max 255 characters).
Date of birth in
YYYY-MM-DD format.ID of the user’s province.
Short biography.
Profile image file. Accepted formats: any image type. Stored under
profile_pics/.Response
Returns the created user object (RegisterSerializer output).
List of group IDs assigned to the user.
The extended profile object if profile data was provided.
POST /api/auth/logout/
Closes the current Django session. The frontend also calls this endpoint when clearing JWT cookies, sending therefresh_token in the request body.
Request body
The current refresh token. Included by the frontend when logging out to allow server-side token invalidation if implemented.
Response
"Logout exitoso" on success.POST /api/auth/forgot-password/
Looks up a user by email and returns a password reset token and UID. The client uses these values to callPOST /api/auth/reset-password-confirm/.
Request body
The email address associated with the account to reset.
Response
"Password reset link generated."Frontend path with
uid and token query parameters: /reset-password-confirm/?uid=<uid>&token=<token>URL-safe base64-encoded user primary key. Pass this to
/api/auth/reset-password-confirm/.Django password reset token. Single-use; expires after Django’s default token timeout.
POST /api/auth/reset-password-confirm/
Resets a user’s password using theuid and token received from /api/auth/forgot-password/.
Request body
URL-safe base64-encoded user primary key from the forgot-password response.
The password reset token from the forgot-password response.
The new password to set for the account.
Response
"Password has been reset successfully."