Skip to main content
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:
The auth config (providers, callbacks, session strategy) lives in @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:
  1. User selects a different organization in the UI
  2. POST /api/auth/update-org is called with the target organizationId
  3. Server validates the user has a membership in that org
  4. 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-org endpoint 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-link route in this app.