The SPS School Backend uses JSON Web Tokens (JWT) for stateless authentication. Every protected endpoint requires a valid token issued at login. Role-based middleware further restricts access so that users can only reach endpoints appropriate to their role.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/praveenarya123/sps-backend/llms.txt
Use this file to discover all available pages before exploring further.
How authentication works
- The client registers a user account via
POST /api/auth/register. - The client logs in via
POST /api/auth/loginand receives a JWT. - Every subsequent request to a protected route includes the raw token in the
Authorizationheader. - The auth middleware verifies the token and attaches the decoded payload (
id,role) toreq.user. - Role middleware (where applied) checks
req.user.roleagainst the required role for the endpoint.
Register a user
POST /api/auth/register
Creates a new user account. The password is hashed with bcrypt before storage.
Request body
Full name of the user.
Email address. Used as the login identifier.
Plaintext password. Stored as a bcrypt hash (
saltRounds: 10).Example request
Response
MongoDB-generated unique identifier for the user.
The name provided at registration.
The email address provided at registration.
The bcrypt hash of the password. Never the plaintext value.
The role assigned to this user.
Log in
POST /api/auth/login
Validates credentials and returns a JWT for use in subsequent requests.
Request body
The user’s registered email address.
The user’s plaintext password.
Example request
Response
A signed JWT. Include this value in the
Authorization header of every protected request.The role of the authenticated user. Use this to determine which endpoints are accessible.
Login error responses
| Status | Condition | Body |
|---|---|---|
404 | No user found with the given email | { "message": "User not found" } |
400 | Email matched but password was incorrect | { "message": "Wrong password" } |
Authenticating requests
Include the token in theAuthorization header of every protected request. The middleware reads the header value directly as the raw token — not in Bearer <token> format.
Example
The token is signed with
JWT_SECRET from your .env file. It encodes the user’s id and role. The token does not expire by default — set an expiresIn option in jwt.sign if you need expiry.Roles
Every user is assigned exactly one role at registration. Role middleware on protected routes comparesreq.user.role to the required role and rejects mismatches with 403.
| Role | Description |
|---|---|
SUPER_ADMIN | Full system access across all domains |
ACADEMIC_ADMIN | Manages academic records and operations |
STUDENT_ADMIN | Manages student records |
FINANCE_ADMIN | Manages fees and financial records |
OPERATIONS_ADMIN | Handles operational administration |
TEACHER | Creates assignments, approves student applications |
STUDENT | Submits assignments, sends applications |
Roles are case-sensitive.
TEACHER is valid; Teacher or teacher will be rejected by role middleware.Auth failure responses
401 Unauthorized — missing or invalid token
Returned byauthMiddleware when the Authorization header is absent or the token fails jwt.verify.
- The
Authorizationheader was not included in the request. - The token was signed with a different
JWT_SECRETthan the server is currently using. - The token value is malformed.
403 Forbidden — insufficient role
Returned byroleMiddleware when the token is valid but the user’s role does not match the required role for the endpoint.
- Calling a
TEACHER-only endpoint with aSTUDENTtoken. - Calling an admin endpoint with a non-admin role.