Authentication Overview
Firebase Google authentication and server session model.
Overview
NimBuild Starter uses Firebase Auth for Google sign-in and HttpOnly server session cookies for server-side authorization. Firebase-specific server code is hidden behind the auth provider adapter so API routes do not depend on Firebase Admin directly. Email/password login, email verification, forgot password, and reset password flows have been removed.
Supported Auth Methods
- Firebase Google sign-in — The only supported user-facing auth method.
Sign-In Flow
- User opens the global sign-in modal.
- If Cloudflare Turnstile is configured, the modal renders the Turnstile check before the Google button. Low-risk visitors pass through automatically; higher-risk visitors complete the visible confirmation control first.
- After Turnstile passes, the modal shows the Google sign-in button.
- Firebase client SDK returns an ID token.
- The browser posts the ID token to
/api/auth/session-login. - The server verifies the token through
modules/auth/provider.tsand creates a server session cookie. modules/auth/user-sync.tssyncs the Firebase user into the localusertable.
Configuration
Firebase client and server adapters live under extensions/auth/firebase:
// Browser SDK
getFirebaseClientAuth();
getGoogleAuthProvider();
// Server provider adapter
firebaseAuthProvider;The browser uses NEXT_PUBLIC_FIREBASE_* values. Server session verification uses FIREBASE_PROJECT_ID, FIREBASE_CLIENT_EMAIL, and FIREBASE_PRIVATE_KEY inside the Firebase extension. Application-facing server code should call modules/auth or modules/auth/provider.ts, not Firebase Admin directly.
Cloudflare Turnstile is optional. When both NEXT_PUBLIC_CLOUDFLARE_TURNSTILE_SITE_KEY and CLOUDFLARE_TURNSTILE_SECRET_KEY are set, features/auth/components/turnstile-gate.tsx gates the Google button and /api/auth/turnstile verifies the token with Cloudflare Siteverify. When either value is missing, the gate is disabled so local development can still sign in.
Session Management
- Sessions are HttpOnly provider-backed session cookies, not database session rows.
- Local user, role, credits, ban status, and plan live in the
usertable. - Session login syncs the local user. Request-time authorization checks the session cookie, resolves the local user, and checks ban status.
- Protected routes and APIs use
getActiveSessionUser()frommodules/auth. getActiveSessionUser()keeps a short in-process cache of local access fields. Admin mutations that change role, ban state, deletion, or access-sensitive plan markers must callinvalidateAuthAccessCache(userId)after a successful write.
Route Protection
| Route Group | Protection |
|---|---|
(protected) | Requires login — redirects to /?auth=login |
(admin) | Requires role='admin' |
(marketing) | Public |