1. Overview
| Field | Value |
|---|---|
| Module Name | Authentication |
| Module Code | AUTH |
| Product | SKOLE (All surfaces) |
| Version | 1.0 |
| Status | Active |
| Business Value | Secures all platform data behind role-appropriate authentication. Each user type (parent, teacher/staff, admin) has a dedicated auth flow. Session tokens with FCM device registration ensure push-notification delivery. |
Scope In
- Parent login via phone number + PIN
- Teacher/Staff login via phone + PIN
- Web Admin login via email + password
- Session/device management
- Logout for all roles
- PIN setup for first-time parents
Scope Out
- OAuth / Social login
- Two-factor authentication (schema reserved, not active)
- Password reset via OTP (available endpoint, not wired to SMS)
2. Requirements
Functional Requirements (FR)
What the module must DO — actions, behaviors, and outcomes.- SKOLE-AUTH-FR001: The module shall allow parents to authenticate using their registered mobile number and a PIN.
- SKOLE-AUTH-FR002: The module shall match both father and mother phone numbers against
parent_details. - SKOLE-AUTH-FR003: The module shall return all linked children’s profiles if the PIN matches.
- SKOLE-AUTH-FR004: The module shall create a
parent_devicesrecord with device info and FCM token on login. - SKOLE-AUTH-FR005: The module shall generate and return a JWT containing
sub,type,skole_id,phone, andsession_token. - SKOLE-AUTH-FR006: The module shall allow teachers to authenticate with phone number and PIN against the
stafftable. - SKOLE-AUTH-FR007: The module shall create a
staff_sessionsrecord on teacher login. - SKOLE-AUTH-FR008: The module shall allow web admins to sign up with name, email, phone, and password.
- SKOLE-AUTH-FR009: The module shall allow web admins to sign in with email and password.
- SKOLE-AUTH-FR010: The module shall invalidate sessions on logout by marking the record as inactive (
is_active = 0). - SKOLE-AUTH-FR011: The module shall allow updating device info (FCM token, platform, model) post-login.
- SKOLE-AUTH-FR012: The module shall provide a PIN setup flow for first-time parent users.
- SKOLE-AUTH-FR013: The module shall allow staff to set or edit passwords separately from the parent flow.
Non-Functional Requirements (NFR)
How well the module must do it — performance, security, and reliability.- SKOLE-AUTH-NFR001: The module shall perform authentication checks ensuring JWT tokens are short-lived and sessions expire after 30 days.
- SKOLE-AUTH-NFR002: The module shall behave securely by ensuring session tokens are unique per device.
- SKOLE-AUTH-NFR003: The module shall behave as a secure gateway by protecting all non-auth routes with a global
JwtAuthGuard. - SKOLE-AUTH-NFR004: The module shall perform bypass logic for auth routes decorated with
@Public(). - SKOLE-AUTH-NFR005: The module shall support JWT extraction via Authorization header, query parameter, or cookie.
Constraints
Rules and boundaries — tech choices and platform restrictions.- C001: We must use PostgreSQL (via Prisma) for persisting users and sessions because it is the platform’s primary data store.
- C002: We must use Firebase FCM for push notification registration to ensure cross-platform delivery.
- C003: We must use standard JWT (
jsonwebtoken) for token signing because the architecture requires stateless authentication.
3. Sub-modules / Backlog
| ID | Sub-module | Priority | Status | Estimate | Linked Requirement |
|---|---|---|---|---|---|
SKOLE-AUTH-SM001 | Parent PIN Authentication | P0 | Done | 3d | FR001–FR005 |
SKOLE-AUTH-SM002 | Teacher PIN Authentication | P0 | Done | 2d | FR006–FR007 |
SKOLE-AUTH-SM003 | Web Admin Signup / Signin | P0 | Done | 2d | FR008–FR009 |
SKOLE-AUTH-SM004 | Session & Device Management | P1 | Done | 2d | FR010–FR011 |
SKOLE-AUTH-SM005 | PIN Setup for New Parents | P1 | Done | 1d | FR012 |
SKOLE-AUTH-SM006 | Staff Password Management | P1 | Done | 1d | FR013 |
4. Logical Implementation
Parent Authentication Flow
Teacher Authentication Flow
Web Admin Signin Flow
JWT Guard Strategy
All API routes are protected globally. The@Public() decorator (custom metadata key isPublic) bypasses the guard. JWT is extracted from:
Authorization: Bearer <token>header?access_token=<token>query parameter- Cookie
access_token
Error Handling
| Scenario | HTTP Code | Message |
|---|---|---|
| Phone not found | 401 | ”Invalid phone number” |
| Wrong PIN | 401 | ”Invalid PIN” |
| Expired session | 401 | ”Unauthorized” |
| Missing roll_no / skole_id | 400 | Field-specific message |
5. UI Requirements
Parent App — Auth Screens
| ID | Screen | Route | Description |
|---|---|---|---|
SKOLE-AUTH-UI001 | PinLoginScreen | /pin-login | Phone number and 4-digit PIN entry for parents |
SKOLE-AUTH-UI002 | ChildSelectionScreen | /child-selection | Screen to select which child to view (for multi-child parents) |
Teacher App — Auth Screens
| ID | Screen | Route | Description |
|---|---|---|---|
SKOLE-AUTH-UI006 | LoginScreen | /login | Phone + PIN single-page login for staff |
Web App — Auth Screen
| ID | Screen | Route | Description |
|---|---|---|---|
SKOLE-AUTH-UI007 | Login Page | /login | Email + password login for school admins |
UI Components
| ID | Component | Props | Used In |
|---|---|---|---|
SKOLE-AUTH-UC001 | PhoneInputField | value, onChange, placeholder | UI001, UI002, UI006 |
SKOLE-AUTH-UC002 | PinInput | length=4, onComplete(pin) | UI003, UI004 |
SKOLE-AUTH-UC003 | AuthButton | label, onPress, loading | All auth screens |
SKOLE-AUTH-UC004 | SchoolLogo | skole_id | UI001, UI006 |
UI States
| Screen | Loading | Empty / First Time | Error |
|---|---|---|---|
| PinLoginScreen | Spinner overlay on submit | Redirect to PinSetup if no PIN set | ”Invalid PIN” toast |
| LoginScreen | Disabled button + spinner | — | “Invalid phone number” toast |
| Web Login | Button spinner | — | Inline error message |
6. Conditional Expressions
| ID | Expression | Trigger | True Action | False Action |
|---|---|---|---|---|
SKOLE-AUTH-CE001 | allParentRecords.length === 0 | POST parent-auth-verification | Return 401 “Invalid phone number” | Proceed to PIN check |
SKOLE-AUTH-CE002 | pinMatches.length === 0 | After phone lookup | Return 401 “Invalid PIN” | Build validParentRecords |
SKOLE-AUTH-CE003 | p.pin === null | Building validParentRecords | Include sibling records (null PIN) | Exclude |
SKOLE-AUTH-CE004 | @Public() decorator present | Every API request | Skip JwtAuthGuard | Enforce JWT check |
SKOLE-AUTH-CE005 | user.pin === null (parent app) | PinLoginScreen render | Redirect to PinSetupScreen | Show PIN entry |
SKOLE-AUTH-CE006 | jwt.type === 'parent' | JWT validation in guard | Attach parent context | Check other type |
SKOLE-AUTH-CE007 | jwt.type === 'staff' | JWT validation | Attach staff context | Check other type |
SKOLE-AUTH-CE008 | session.is_active === 0 | Any authenticated request | 401 Unauthorized | Allow request |
7. Internal Module Connections
| Direction | Module | Data / Event | Condition |
|---|---|---|---|
| AUTH → STUD | Student Management | Children list returned on login | Always on successful parent auth |
| AUTH → PROF | Profile | Parent profile data embedded in auth response | Always |
| AUTH → NOTF | Notifications | FCM token stored in parent_devices / staff record | On login / device update |
| STUD → AUTH | Student Management | roll_no, skole_id used to scope auth | Always |
| All modules → AUTH | Every module | JWT session_token, skole_id, sub used in every request | All protected routes |
8. External Connections
| ID | Service | Purpose | Auth Method | Failure Behavior |
|---|---|---|---|---|
SKOLE-AUTH-EX001 | PostgreSQL (via Prisma) | Persist users, sessions, parent_details | DB credentials via DATABASE_URL env | 500 Internal Server Error |
SKOLE-AUTH-EX002 | Firebase FCM | Push notification token registration | Firebase Admin SDK (server key) | Auth succeeds, notifications silently fail |
SKOLE-AUTH-EX003 | JWT (jsonwebtoken) | Token signing / verification | JWT_SECRET env variable | 401 Unauthorized |
9. Database Tables
| ID | Table | Role |
|---|---|---|
SKOLE-AUTH-TB001 | users | Web admin accounts |
SKOLE-AUTH-TB002 | parent_details | Parent phone, PIN, email, FCM token |
SKOLE-AUTH-TB003 | parent_devices | Device sessions for parents (unique session_token) |
SKOLE-AUTH-TB004 | staff | Staff records including PIN and FCM token |
SKOLE-AUTH-TB005 | staff_sessions | Device sessions for staff (unique session_token) |
SKOLE-AUTH-TB006 | user_sessions | Device sessions for web admins |
Key Relationships
parent_devices.parent_id→parent_details.idparent_details.student_roll_no+parent_details.skole_id→students.roll_no+students.skole_idstaff_sessions.staff_id→staff.iduser_sessions.user_id→users.id
10. API Endpoints Summary
| ID | Method | Route | Auth | Description |
|---|---|---|---|---|
SKOLE-AUTH-EP001 | POST | /parent-app/parent-auth-verification | Public | Parent phone+PIN login |
SKOLE-AUTH-EP002 | POST | /parent-app/logout | JWT (parent) | Invalidate parent session |
SKOLE-AUTH-EP003 | PUT | /parent-app/auth/device-info | JWT (parent) | Update device/FCM info |
SKOLE-AUTH-EP004 | POST | /teachers-app/teacher-auth-verification | Public | Teacher phone+PIN login |
SKOLE-AUTH-EP005 | POST | /teachers-app/logout | JWT (staff) | Invalidate staff session |
SKOLE-AUTH-EP006 | POST | /web-app/signup | Public | Create admin account |
SKOLE-AUTH-EP007 | POST | /web-app/signin | Public | Admin email+password login |
SKOLE-AUTH-EP008 | POST | /web-app/reset-password | Public | Reset admin password |
SKOLE-AUTH-EP009 | POST | /web-app/parent-set-password | Public | Set parent PIN (first time) |
SKOLE-AUTH-EP010 | PATCH | /web-app/parent-edit-password | Public | Edit parent PIN |
SKOLE-AUTH-EP011 | POST | /web-app/staff-set-password | Public | Set staff PIN (first time) |
SKOLE-AUTH-EP012 | PATCH | /web-app/staff-edit-password | Public | Edit staff PIN |
SKOLE-AUTH-EP013 | POST | /web-app/logout | JWT (user) | Invalidate admin session |
- Old devices can be logged out via separate endpoint
EP001: Parent Phone+PIN Login
Section 1: Endpoint Summary
Authenticates parent users using their registered phone number and PIN. Returns JWT token, parent profile, and all linked children for multi-child families.Section 2: HTTP Details
- HTTP Method: POST
- Endpoint URL:
/parent-app/parent-auth-verification - Content-Type:
application/json - Authentication: Public (no token required)
- Rate Limit: 5 requests per minute per IP
Section 3: Path Parameters
None requiredSection 4: Query Parameters
None requiredSection 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 7: Error Responses
400 - Bad RequestSection 8: Implementation Examples
JavaScript (Node.js/React Native):Section 9: Database Context
Primary Table:parent_details
- Primary Key:
id(UUID) - School Isolation:
skole_id
- SELECT * FROM parent_details WHERE (father_phone = ? OR mother_phone = ?) AND skole_id = ?
- Verify: password.verify(pin, parent.pin_hash)
- SELECT * FROM students WHERE parent_id = ? AND status = ‘active’
- INSERT INTO parent_devices (parent_id, session_token, fcm_token, device_info, created_at)
- father_phone (for query performance)
- mother_phone (for query performance)
- skole_id (for school isolation)
- session_token (for session lookup)
Section 10: Business Logic & Validations
Validation Rules:- phone_no: 10-15 digits, with or without country code, must exist in parent_details
- pin: 4-6 digits, bcrypt hashed in database
- skole_id: Must match user’s school
- device_info: Optional but recommended
- No prior authentication required (public endpoint)
- After login, JWT validates on all subsequent requests
- Parent can only access their own children and school data
- Search for parent by father_phone or mother_phone
- If found, verify PIN against bcrypt hash
- If PIN matches, collect all active children linked to parent
- Generate unique session_token (UUID) with 30-day expiry
- Create parent_devices record for multi-device tracking
- Update FCM token for push notifications
- Sign JWT with parent type and return access_token
- PIN is never returned in response (masked as ****)
- If parent has no PIN set, redirect to PIN setup flow
- Multiple devices supported per parent (multi-login)
- Old devices can be logged out via separate endpoint
Section 11: Related Endpoints
- PUT
/parent-app/auth/device-info- Update device FCM token - POST
/parent-app/logout- Logout and invalidate session - POST
/web-app/parent-set-password- Setup PIN for first time - PATCH
/web-app/parent-edit-password- Change existing PIN - GET
/parent-app/student- Get children after login
Section 12: Response Summary Table
| Status | Scenario | Error Code | Message |
|---|---|---|---|
| 200 ✅ | Success | - | Authentication successful |
| 400 ❌ | Missing fields | VALIDATION_ERROR | Validation failed |
| 401 ❌ | Phone not found | INVALID_PHONE | Phone number not registered |
| 401 ❌ | Wrong PIN | INVALID_PIN | Incorrect PIN |
| 429 ❌ | Rate limit | RATE_LIMITED | Too many login attempts |
| 500 ❌ | Server error | INTERNAL_ERROR | Server error occurred |
EP002: Parent Logout
Section 1: Endpoint Summary
Invalidates parent session by marking the device session as inactive, effectively logging out the parent from that specific device.Section 2: HTTP Details
- HTTP Method: POST
- Endpoint URL:
/parent-app/logout - Content-Type:
application/json - Authentication: JWT Bearer Token (Required - Parent)
- Rate Limit: Unlimited
Section 3: Path Parameters
NoneSection 4: Query Parameters
| Parameter | Type | Required | Default | Description | Example |
|---|---|---|---|---|---|
| skole_id | UUID | No | From JWT | School identifier (optional override) | 550e8400-e29b-41d4-a716-446655440000 |
Section 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 7: Error Responses
401 - UnauthorizedSection 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables Affected:parent_devices- Mark is_active = 0- Query: UPDATE parent_devices SET is_active = 0 WHERE session_token = ? AND parent_id = ?
- If logout_all_devices = false: Only invalidate current session_token
- If logout_all_devices = true: Invalidate all session_tokens for the parent
Section 10: Business Logic & Validations
Validation:- JWT must be valid and not expired
- Parent must have an active session
- session_token must exist in parent_devices
- Extract session_token from JWT
- Find parent_devices record where session_token matches
- Mark is_active = 0
- If logout_all_devices = true, also mark all other devices as inactive
- Return success message
Section 11: Related Endpoints
- POST
/parent-app/parent-auth-verification- Login again - PUT
/parent-app/auth/device-info- Manage device tokens - GET
/parent-app/profile- Get parent profile after login
Section 12: Response Summary Table
| Status | Scenario | Error Code | Message |
|---|---|---|---|
| 200 ✅ | Success | - | Logged out successfully |
| 401 ❌ | Invalid token | UNAUTHORIZED | Authorization header missing or invalid |
| 404 ❌ | Session not found | SESSION_NOT_FOUND | Active session not found |
| 500 ❌ | Database error | INTERNAL_ERROR | Server error occurred |
EP003: Update Parent Device Info
Section 1: Endpoint Summary
Updates device information (FCM token, platform, model) for push notification delivery without requiring re-login.Section 2: HTTP Details
- HTTP Method: PUT
- Endpoint URL:
/parent-app/auth/device-info - Content-Type:
application/json - Authentication: JWT Bearer Token (Required - Parent)
- Rate Limit: 100 requests per minute
Section 3: Path Parameters
NoneSection 4: Query Parameters
NoneSection 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 7: Error Responses
400 - Invalid FCM TokenSection 8: Implementation Examples
JavaScript:Section 9: Database Context
Table:parent_devices Update Query: UPDATE parent_devices SET fcm_token = ?, platform = ?, model = ?, os_version = ?, updated_at = NOW() WHERE session_token = ?
Section 10: Business Logic & Validations
Validation:- FCM token must be valid format
- Platform must be one of: ios, android, web
- JWT must be valid
- Extract session_token from JWT
- Find parent_devices record
- Update fcm_token, platform, model, os_version
- Return updated device information
Section 11: Related Endpoints
- POST
/parent-app/logout- Logout device - POST
/parent-app/parent-auth-verification- Initial login
Section 12: Response Summary Table
| Status | Scenario | Error Code | Message |
|---|---|---|---|
| 200 ✅ | Success | - | Device information updated |
| 400 ❌ | Invalid FCM | INVALID_FCM_TOKEN | FCM token format invalid |
| 401 ❌ | Unauthorized | UNAUTHORIZED | Invalid or expired JWT |
| 500 ❌ | Server error | INTERNAL_ERROR | Server error occurred |
12. Summary Table: All 13 Authentication Endpoints
| ID | Endpoint | Method | Auth | Description | Status |
|---|---|---|---|---|---|
| EP001 | /parent-app/parent-auth-verification | POST | Public | Parent login | ✅ Documented |
| EP002 | /parent-app/logout | POST | JWT | Parent logout | ✅ Documented |
| EP003 | /parent-app/auth/device-info | PUT | JWT | Update device info | ✅ Documented |
| EP004 | /teachers-app/teacher-auth-verification | POST | Public | Teacher login | ⏳ See EP001 pattern |
| EP005 | /teachers-app/logout | POST | JWT | Teacher logout | ⏳ See EP002 pattern |
| EP006 | /web-app/signup | POST | Public | Admin signup | ⏳ Coming |
| EP007 | /web-app/signin | POST | Public | Admin login | ⏳ Coming |
| EP008 | /web-app/reset-password | POST | Public | Password reset | ⏳ Coming |
| EP009 | /web-app/parent-set-password | POST | Public | Setup parent PIN | ⏳ Coming |
| EP010 | /web-app/parent-edit-password | PATCH | Public | Change parent PIN | ⏳ Coming |
| EP011 | /web-app/staff-set-password | POST | Public | Setup staff PIN | ⏳ Coming |
| EP012 | /web-app/staff-edit-password | PATCH | Public | Change staff PIN | ⏳ Coming |
| EP013 | /web-app/logout | POST | JWT | Admin logout | ✅ Documented |
EP004: Teacher Phone+PIN Login
Section 1: Endpoint Summary
Authenticates teacher/staff users using registered phone number and PIN. Returns JWT token and staff profile with assigned classes.Section 2: HTTP Details
- HTTP Method: POST
- Endpoint URL:
/teachers-app/teacher-auth-verification - Content-Type:
application/json - Authentication: Public
- Rate Limit: 5 requests per minute per IP
Section 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 7: Error Responses
401 - Phone/PIN InvalidSection 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables:staff_details- Teacher/admin staff recordsstaff_class_assignments- Assigned classes
- phone_no (for lookup)
- skole_id (for school isolation)
Section 10: Business Logic & Validations
Validation:- phone_no must exist in staff_details
- pin must match bcrypt hash
- Staff must be active status
- Must belong to correct school (skole_id)
- Find staff by phone_no and skole_id
- Verify PIN
- Load all assigned classes
- Generate JWT with staff role
- Create staff_devices session record
- Return token and profile
Section 11: Related Endpoints
- POST
/teachers-app/logout- Logout - GET
/teachers-app/classes- Get assigned classes - GET
/teachers-app/students- Get students by class
Section 12: Response Summary Table
| Status | Scenario | Error Code | Message |
|---|---|---|---|
| 200 ✅ | Success | - | Authentication successful |
| 401 ❌ | Invalid | INVALID_CREDENTIALS | Phone or PIN incorrect |
| 429 ❌ | Rate limited | RATE_LIMITED | Too many attempts |
EP005: Teacher Logout
Section 1: Endpoint Summary
Invalidates teacher session, effectively logging them out from the app.Section 2: HTTP Details
- HTTP Method: POST
- Endpoint URL:
/teachers-app/logout - Authentication: JWT Bearer Token (Staff)
Section 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 7: Error Responses
401 - UnauthorizedSection 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables:staff_devices- Mark is_active = 0
Section 10: Business Logic & Validations
Mark session_token as inactive in staff_devices table.Section 11: Related Endpoints
- POST
/teachers-app/teacher-auth-verification- Login
Section 12: Response Summary Table
| Status | Scenario | Error Code |
|---|---|---|
| 200 ✅ | Success | - |
| 401 ❌ | Unauthorized | UNAUTHORIZED |
EP006: Admin Signup
Section 1: Endpoint Summary
Creates new admin account with email and password. First admin in a school requires special code/invitation.Section 2: HTTP Details
- HTTP Method: POST
- Endpoint URL:
/web-app/signup - Authentication: Public (with optional invitation code)
Section 5: Request Body Schema
Section 6: Response Schema (Success - 201)
Section 7: Error Responses
400 - Email ExistsSection 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables:users- Admin user recordsschools- School codes validation
Section 10: Business Logic & Validations
Validation:- Email format valid and unique
- Password strength check (8+ chars, uppercase, number, special char)
- School code exists and valid
- Invitation code not expired
- Validate email uniqueness
- Check password strength
- If school_code provided, verify and create school + admin
- If invitation_code provided, verify it’s valid and not expired
- Hash password with bcrypt
- Create user and admin_role records
- Return confirmation
Section 11: Related Endpoints
- POST
/web-app/signin- Login with created account - POST
/web-app/reset-password- Password reset
Section 12: Response Summary Table
| Status | Scenario | Error Code | Message |
|---|---|---|---|
| 201 ✅ | Success | - | Account created |
| 400 ❌ | Email exists | EMAIL_EXISTS | Already registered |
| 400 ❌ | Weak password | WEAK_PASSWORD | Password requirements |
| 400 ❌ | Invalid code | INVALID_CODE | Code invalid |
EP007: Admin Email+Password Login
Section 1: Endpoint Summary
Authenticates admin users using email and password. Returns JWT token with admin profile and school information.Section 2: HTTP Details
- HTTP Method: POST
- Endpoint URL:
/web-app/signin - Authentication: Public
Section 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 7: Error Responses
401 - Invalid CredentialsSection 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables:users- User recordsadmin_roles- Admin role assignmentsschools- School details
Section 10: Business Logic & Validations
Validation:- Email exists in users table
- Password matches bcrypt hash
- User has admin role
- Account not suspended
- Find user by email
- Verify password
- Check if admin role exists
- Load school information
- Generate JWT (1 day expiry)
- If remember_me, generate refresh token (30 days)
- Return tokens and profile
Section 11: Related Endpoints
- POST
/web-app/reset-password- Reset password - POST
/web-app/logout- Logout - GET
/web-app/profile- Get admin profile
Section 12: Response Summary Table
| Status | Scenario | Error Code | Message |
|---|---|---|---|
| 200 ✅ | Success | - | Login successful |
| 401 ❌ | Invalid | INVALID_CREDENTIALS | Email/password incorrect |
| 403 ❌ | Not admin | FORBIDDEN | User not admin |
EP008: Request Password Reset
Section 1: Endpoint Summary
Sends password reset email link for admin accounts. Generates time-limited reset token (valid 1 hour).Section 2: HTTP Details
- HTTP Method: POST
- Endpoint URL:
/web-app/reset-password - Authentication: Public
Section 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 7: Error Responses
404 - Email Not FoundSection 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables:password_resets- Store reset token, email, expires_at- TTL: 1 hour, auto-cleanup for expired records
Section 10: Business Logic & Validations
Validation:- Email exists in users table
- No active reset token for this email (or expired)
- Find user by email
- Generate random reset token (32 chars)
- Save to password_resets with 1-hour expiry
- Send email with reset link
- Return confirmation (don’t expose token)
Section 11: Related Endpoints
- POST
/web-app/confirm-reset- Verify token and set new password - POST
/web-app/signin- Login
Section 12: Response Summary Table
| Status | Scenario | Error Code | Message |
|---|---|---|---|
| 200 ✅ | Success | - | Reset link sent |
| 404 ❌ | Not found | EMAIL_NOT_FOUND | Email not registered |
EP009: Set Parent PIN (First Time)
Section 1: Endpoint Summary
Parents set their initial 4-digit PIN. Requires parent invitation/verification code from admin. Used during initial parent account activation.Section 2: HTTP Details
- HTTP Method: POST
- Endpoint URL:
/web-app/parent-set-password - Authentication: Public (with activation code)
Section 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 7: Error Responses
400 - Invalid PIN FormatSection 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables:parent_details- Update pin_hashparent_activations- Track activation codes (TTL: 7 days)
Section 10: Business Logic & Validations
Validation:- PIN format: 4-6 digits only
- PIN matches confirm_pin
- activation_code exists and not expired
- parent_id matches activation code
- Parent doesn’t already have a PIN set
- Validate PIN format
- Verify activation_code for this parent_id
- Hash PIN with bcrypt
- Update parent_details with pin_hash
- Mark activation as completed
- Return success
Section 11: Related Endpoints
- POST
/parent-app/parent-auth-verification- Login after PIN set - PATCH
/web-app/parent-edit-password- Change PIN later
Section 12: Response Summary Table
| Status | Scenario | Error Code | Message |
|---|---|---|---|
| 200 ✅ | Success | - | PIN set successfully |
| 400 ❌ | Invalid format | INVALID_PIN_FORMAT | Must be 4-6 digits |
| 400 ❌ | PIN mismatch | PIN_MISMATCH | Pins don’t match |
| 400 ❌ | Code expired | INVALID_ACTIVATION_CODE | Code invalid |
EP010: Update Parent PIN
Section 1: Endpoint Summary
Parents change their existing PIN. Requires old PIN verification for security.Section 2: HTTP Details
- HTTP Method: PATCH
- Endpoint URL:
/web-app/parent-edit-password - Authentication: Public (with parent identification)
Section 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 7: Error Responses
401 - Old PIN IncorrectSection 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables:parent_details- Update pin_hash, updated_at
Section 10: Business Logic & Validations
Verify old PIN, validate new PIN format, update in database.Section 11: Related Endpoints
- POST
/parent-app/parent-auth-verification- Login with new PIN - POST
/web-app/parent-set-password- Initial setup
Section 12: Response Summary Table
| Status | Scenario | Error Code | Message |
|---|---|---|---|
| 200 ✅ | Success | - | PIN updated |
| 401 ❌ | Wrong old PIN | INVALID_OLD_PIN | Incorrect old PIN |
EP011: Set Teacher PIN (First Time)
Section 1: Endpoint Summary
Teachers set their initial 4-digit PIN during account activation.Section 2: HTTP Details
- HTTP Method: POST
- Endpoint URL:
/web-app/staff-set-password - Authentication: Public (with activation code)
Section 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables:staff_details- Update pin_hashstaff_activations- Verify activation code
Section 12: Response Summary Table
| Status | Scenario | Error Code |
|---|---|---|
| 200 ✅ | Success | - |
| 400 ❌ | Invalid | FORMAT_ERROR |
EP012: Update Teacher PIN
Section 1: Endpoint Summary
Teachers change their existing PIN with old PIN verification.Section 2: HTTP Details
- HTTP Method: PATCH
- Endpoint URL:
/web-app/staff-edit-password - Authentication: Public
Section 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables:staff_details- Update pin_hash
Section 12: Response Summary Table
| Status | Scenario | Error Code |
|---|---|---|
| 200 ✅ | Success | - |
| 401 ❌ | Wrong PIN | INVALID_OLD_PIN |
EP013: Admin Logout
Section 1: Endpoint Summary
Invalidates admin JWT token and ends the session.Section 2: HTTP Details
- HTTP Method: POST
- Endpoint URL:
/web-app/logout - Authentication: JWT Bearer Token (Required)
Section 5: Request Body Schema
Section 6: Response Schema (Success - 200)
Section 7: Error Responses
401 - UnauthorizedSection 8: Implementation Examples
JavaScript:Section 9: Database Context
Tables:sessions- Revoke session token or mark as inactive
Section 10: Business Logic & Validations
Extract and invalidate JWT session.Section 11: Related Endpoints
- POST
/web-app/signin- Login again
Section 12: Response Summary Table
| Status | Scenario | Error Code |
|---|---|---|
| 200 ✅ | Success | - |
| 401 ❌ | Unauthorized | UNAUTHORIZED |