1818| Database | Cloudflare D1 (SQLite) | Cloudflare |
1919| Vector Search | Cloudflare Vectorize | Cloudflare |
2020| AI/ML | Workers AI (embeddings, LLMs) | Cloudflare |
21- | Auth | Stytch OAuth | Stytch |
21+ | Auth | Stytch Consumer SDK | Stytch |
2222| Storage | Cloudflare R2 | Cloudflare |
2323| Cache | Cloudflare KV | Cloudflare |
2424
@@ -29,7 +29,8 @@ nhimbe/
2929├── src/ # Next.js frontend
3030│ ├── app/ # App Router (file-based routing)
3131│ │ ├── api/ # Route handlers (auth callbacks, OG images)
32- │ │ ├── auth/ # Auth pages (signin, callback, error)
32+ │ │ ├── auth/ # Auth pages (signin, error)
33+ │ │ ├── authenticate/ # Stytch magic link token exchange
3334│ │ ├── events/ # Event pages (browse, create, [id] details)
3435│ │ ├── my-events/ # User's RSVPed/hosted events
3536│ │ ├── search/ # AI-powered search
@@ -38,7 +39,7 @@ nhimbe/
3839│ │ ├── onboarding/ # New user flow
3940│ │ └── globals.css # Theme system & global styles
4041│ ├── components/ # React components
41- │ │ ├── auth/ # AuthContext provider
42+ │ │ ├── auth/ # AuthContext, StytchProvider
4243│ │ ├── layout/ # Header, Footer
4344│ │ └── ui/ # Reusable components (cards, badges, etc.)
4445│ └── lib/ # Utilities
@@ -50,7 +51,7 @@ nhimbe/
5051│ └── src/
5152│ ├── index.ts # Main API router (~2700 lines)
5253│ ├── types.ts # TypeScript definitions
53- │ ├── auth/stytch.ts # OAuth token handling
54+ │ ├── auth/stytch.ts # Stytch session JWT validation
5455│ ├── ai/ # AI features
5556│ │ ├── search.ts # RAG semantic search
5657│ │ ├── assistant.ts # AI chat (Shamwari)
@@ -205,7 +206,7 @@ POST /api/media/upload # Upload media
205206### Auth Endpoints
206207
207208```
208- POST /api/auth/token # OAuth token exchange
209+ POST /api/auth/sync # Sync Stytch session with backend user
209210GET /api/auth/me # Current user
210211POST /api/auth/logout # Logout
211212POST /api/auth/onboarding # Complete onboarding
@@ -244,13 +245,10 @@ Always lowercase: **nhimbe** (even at sentence start)
244245### Frontend (.env.local)
245246
246247``` bash
248+ NEXT_PUBLIC_STYTCH_PUBLIC_TOKEN=public-token-live-xxxxx
247249NEXT_PUBLIC_API_URL=http://localhost:8787
248- NEXT_PUBLIC_STYTCH_CLIENT_ID=your-client-id
249- NEXT_PUBLIC_GOOGLE_MAPS_API_KEY=your-maps-key
250- NEXT_PUBLIC_MUKOKO_CLIENT_ID=your-client-id
251- NEXT_PUBLIC_MUKOKO_REDIRECT_URI=http://localhost:3000/api/auth/callback
252250NEXT_PUBLIC_SITE_URL=http://localhost:3000
253- MUKOKO_CLIENT_SECRET =your-secret
251+ NEXT_PUBLIC_GOOGLE_MAPS_API_KEY =your-maps-key
254252```
255253
256254### Backend (worker/.dev.vars)
@@ -260,8 +258,6 @@ ENVIRONMENT=development
260258API_KEY=your-api-key
261259STYTCH_PROJECT_ID=your-project-id
262260STYTCH_SECRET=your-secret
263- STYTCH_CLIENT_ID=your-client-id
264- STYTCH_CLIENT_SECRET=your-client-secret
265261```
266262
267263## Cloudflare Bindings
@@ -295,10 +291,10 @@ STYTCH_CLIENT_SECRET=your-client-secret
295291
296292### Authentication
297293
298- - Stytch OAuth 2.0 + PKCE flow
299- - Token storage in httpOnly cookies
300- - Client-side user data in localStorage
301- - Auto token refresh
294+ - Stytch Consumer SDK with email magic links and OTP
295+ - Stytch session JWT validation on backend
296+ - Session managed by Stytch SDK (automatic cookie handling)
297+ - Backend sync via ` /api/auth/sync ` after authentication
302298
303299## Common Tasks
304300
@@ -369,10 +365,9 @@ npm run deploy --env staging # Staging
369365
370366## Security Considerations
371367
372- - PKCE flow for OAuth
368+ - Stytch session JWT validation on all protected endpoints
373369- API key required for write operations
374370- CORS whitelist in backend
375- - httpOnly cookies for tokens
376371- Input sanitization
377372- No secrets in code (use .dev.vars)
378373
0 commit comments