Global Conventions
Authentication Strategy
All endpoints (unless marked Public) require a valid JSON Web Token (JWT). The token can be provided via theAuthorization: Bearer header, the access_token query parameter, or a cookie.
Multi-Tenancy
Most requests in the Teacher and Web modules require askole_id (School Identifier) to ensure data isolation.
Authentication API Documentation (Complete Specification)
1. API Purpose
The Authentication module provides the secure entry point for all users of the Skole platform. It validates identities against role-specific data stores and issues JWT tokens that encapsulate user permissions and school context. Capabilities:- Single-page login for Parents and Staff using Phone + PIN.
- Email/Password authentication for Web Administrators.
- Secure session creation and device registration for push notifications.
- Remote session invalidation and multi-device support.
2. Endpoint Definition
| Property | Value |
|---|---|
| Endpoint Group | Authentication Services |
| HTTP Methods | POST, PUT, PATCH |
| Base Paths | /parent-app, /teachers-app, /web-app |
| Primary Tech | NestJS + JWT + Prisma |
Core Auth Endpoints
| Method | Route | Auth | Description |
|---|---|---|---|
| POST | /parent-app/parent-auth-verification | 🔓 Public | Parent login (Phone/Email + PIN) |
| POST | /teachers-app/teacher-auth-verification | 🔓 Public | Teacher/Staff login (Phone + PIN) |
| POST | /web-app/signin | 🔓 Public | Admin login (Email + Password) |
| POST | /web-app/signup | 🔓 Public | Admin registration |
| POST | /web-app/logout | 🔐 JWT | Invalidate current session |
3. Authentication Flow
- Submission: Client sends credentials (e.g., Phone + PIN) to the appropriate module endpoint.
- Identification: System queries role-specific tables (
parent_details,staff, orusers). - Validation: System performs PIN/Password verification via
bcrypt. - Session Creation: A unique
session_tokenis generated and stored in a sessions table (parent_devices,staff_sessions, oruser_sessions). - JWT Issuance: System signs a JWT containing
sub(user_id),skole_id,type, and thesession_token. - Interaction: Client stores the token and includes it in the
Authorizationheader for all subsequent requests.
4. Request Structure
POST /parent-app/parent-auth-verification
Request Body:POST /teachers-app/teacher-auth-verification
Request Body:POST /web-app/signin
Request Body:POST /web-app/signup
Request Body:5. Response Structure
Success: Parent Login (200 OK)
Route:/parent-app/parent-auth-verification
Success: Teacher Login (200 OK)
Route:/teachers-app/teacher-auth-verification
Success: Admin Signin (200 OK)
Route:/web-app/signin
Success: Admin Signup (201 Created)
Route:/web-app/signup
Success: Logout (200 OK)
Route:/{module}/logout
6. Error Responses
| HTTP Code | Error Code | Description |
|---|---|---|
| 401 | UNAUTHORIZED | Invalid phone number or PIN |
| 403 | FORBIDDEN | Account disabled or school access revoked |
| 400 | BAD_REQUEST | Missing required fields (e.g., skole_id) |
| 500 | SERVER_ERROR | Internal database or JWT signing error |
7. Security Considerations
- PIN Security: PINs are never stored in plain text; they are hashed using
bcryptwith a salt factor of 10. - Token Expiry: Mobile sessions are long-lived (30 days) but can be revoked remotely via the Sessions API.
- Tenant Isolation: The
skole_idis embedded in the JWT and enforced by a globalSkoleGuardto prevent cross-school data leaks.
8. Token Usage
Users must include the token in theAuthorization header:
9. Token Refresh
Token rotation is handled during the login phase. If a token is near expiry, the client should perform a silent re-authentication or use the specific refresh flow (where available).10. Logout / Session Invalidation
Endpoint:POST /{module}/logout
This endpoint marks the session_token as inactive in the database. Even if the JWT has not expired, the API will reject any request containing an invalidated session token.
11. Usage Example (cURL)
12. Notes / Special Behaviors
- Sibling Logic: If a parent has multiple children in the same school, the auth response returns a consolidated list of all children linked to that phone number/PIN.
- FCM Registration: The
fcm_tokenprovided during login is automatically linked to the session, enabling real-time push notifications for that specific device.