Internal documentation for developers. This page covers the authentication layer, session structure, organization switching, and invite flows. Not intended for end users.
Route Map
NextAuth Handler
The[...nextauth] route is a thin wrapper around @zappway/lib/auth:
@zappway/lib/auth. This route only delegates to it.
Session Object (AppRouteRequest.session)
All authenticated routes receive an AppRouteRequest with a populated session:
Organization Switching (update-org)
Users can belong to multiple organizations. The update-org endpoint updates the active organization in the session.
Flow:
- User selects a different organization in the UI
POST /api/auth/update-orgis called with the targetorganizationId- Server validates the user has a membership in that org
- Session cookie is refreshed with the new org context
Invite Flow (invite)
Admin Sync (admin-sync)
Internal endpoint used to synchronize admin-tier organization memberships (e.g., after a plan upgrade). Called by billing webhooks via server-side HTTP (not from the client).
withPermissionRoute Auth Modes
Use
authMode: 'lightweight' for all read endpoints to reduce latency.
Permission Check Pattern
Known Issues / Gotchas
runtime = "nodejs"is required on the[...nextauth]route — the auth library uses Node.js-only APIs not available in Edge Runtime.- Session cookies are HTTPOnly and scoped to the domain. Never try to read them from client-side JS.
- The
update-orgendpoint must invalidate any active WebSocket/SSE connections for the user so that real-time updates reflect the new org context. - Magic link auth (if enabled via the lib) is handled by NextAuth’s email provider internally — there is no separate
verify-magic-linkroute in this app.

