PageSpace uses a custom opaque session-based authentication system with multiple providers and token types.
| Token | Prefix | Lifetime | Use Case |
|---|---|---|---|
| Session | ps_sess_ | Configurable | Web authentication |
| Device | ps_dev_ | Long-lived | Desktop/mobile persistent auth |
| Socket | ps_sock_ | 5 minutes | WebSocket authentication |
| Email Unsubscribe | ps_unsub_ | One-time use | Email unsubscribe links |
| MCP | mcp_ | No expiration | API access for external tools |
All tokens are opaque — they contain no embedded data. They're random strings with type prefixes for debugging.
User login → Generate random token → Hash with SHA-256 → Store hash in DB
↓
Set HTTP-only cookie with raw token
↓
Subsequent request → Hash cookie value → Look up hash in DB → Validate
Standard email/password authentication with:
OAuth 2.0 flow with Google:
POST /api/auth/google/signinGET /api/auth/google/callbackHardware-backed authentication using passkeys:
Device tokens support automatic rotation:
The tokenVersion field on the user record enables global session invalidation:
tokenVersiontokenVersion| Endpoint | Limit | Scope |
|---|---|---|
| Login | Configurable | Per IP + per email |
| Token refresh | Configurable | Per user |
| Signup | Configurable | Per IP |
Rate limits reset on successful authentication.
MCP tokens are long-lived API tokens for external tool access:
POST /api/auth/mcp-tokensMCP tokens authenticate API requests via the Authorization: Bearer mcp_... header.
If a refresh token is reused (indicating potential theft):
HttpOnly: true — Not accessible to JavaScript
Secure: true — Only sent over HTTPS
SameSite: Lax — CSRF protection
Domain: configured — Scoped to your domain
Path: / — Available site-wide
All authentication events are logged:
Logs include device information, IP address, and user agent for audit trails.
| Method | Route | Description |
|---|---|---|
| POST | /api/auth/signup | Register with email/password |
| POST | /api/auth/login | Authenticate with email/password |
| POST | /api/auth/logout | Invalidate session |
| GET | /api/auth/me | Get current user |
| POST | /api/auth/refresh | Refresh access token |
| GET | /api/auth/csrf | Get CSRF token |
| GET/POST | /api/auth/google/signin | Initiate Google OAuth |
| GET | /api/auth/google/callback | Handle OAuth callback |
| GET/POST | /api/auth/mcp-tokens | List/create MCP tokens |
| DELETE | /api/auth/mcp-tokens/[id] | Revoke MCP token |
Search docs, blog posts, and more.