Skip to content

Auth System Reference ​

Architecture ​

Three-tier role hierarchy: SuperAdmin → Admin → Customer

  • SuperAdmin: manages the entire platform (orgs, admins)
  • Admin: owns an organization, manages customers
  • Customer: uses the Oktivo platform (campaigns, agents, calls)

Every document is scoped by organizationId to prevent cross-tenant data leaks.

Auth Flow ​

Login → JWT access token (15m) + refresh token (7d)
Request → Authorization: Bearer <accessToken>
401 → Client sends refresh token → New token pair
Refresh fails → Redirect to /login

API Routes ​

Auth (no JWT required) ​

MethodPathDescription
POST/auth/loginUniversal login (all roles)
POST/auth/admin/signupAdmin self-signup with org creation
POST/auth/refreshRefresh token pair

Auth (JWT required) ​

MethodPathDescription
POST/auth/logoutInvalidate session
GET/auth/meCurrent user + organization info

Admin Routes (JWT + admin role) ​

MethodPathDescription
GET/admin/customersList org customers (paginated)
GET/admin/customers/:idGet customer detail
POST/admin/customersCreate customer
PUT/admin/customers/:idUpdate customer
PUT/admin/customers/:id/reset-passwordReset customer password
GET/admin/organizationGet org info + stats
PUT/admin/organization/brandingUpdate org branding

SuperAdmin Routes (JWT + superadmin role) ​

MethodPathDescription
GET/superadmin/dashboardPlatform-wide stats
GET/superadmin/organizationsList all orgs (paginated)
GET/superadmin/organizations/:idOrg detail
POST/superadmin/organizationsCreate org + admin
PUT/superadmin/organizations/:idUpdate org

Campaign System (JWT required, mounted at root /) ​

MethodPathDescription
POST/upload-campaignUpload campaign with CSV
GET/campaignsList user's campaigns
GET/campaigns/:idGet campaign details
DELETE/campaigns/:uidDelete campaign
POST/start-campaign/:uidStart campaign
POST/stop-campaign/:uidStop campaign
POST/create-agentCreate agent
PUT/update-agent/:idUpdate agent
DELETE/delete-agent/:idDelete agent
POST/test-agentTest call agent
GET/campaign-detail/:idFull campaign detail with contacts
GET/call-summary/:phone/:uid/:contactUIDCall summary
GET/export-campaign/:idCSV export
GET/export-campaign-full/:idFull export
GET/recording/:phone/:idRecording signed URL

Webhooks (no JWT called by external services) ​

MethodPathDescription
POST/webhook/call-statusCall status update
POST/webhook/call-voiceVoice recording webhook

JWT Payload ​

ts
{
  userId: string;       // MongoDB _id
  role: "superadmin" | "admin" | "customer";
  organizationId: string;  // null for superadmin
}

After verifyJwt middleware, these are available as req.userId, req.role, req.organizationId.

Entry Point ​

  • Source: src/server.ts
  • Compiled: dist/server.js
  • No more index.js single TypeScript entry point

Build & Run ​

bash
npm run build    # Compile TS → dist/
npm start        # Run dist/server.js
npm run dev      # ts-node with watch (development)

Last updated: