Buildml delegates all authentication to NextAuth.js v5 using Google as the sole OAuth provider. Sessions are stored as signed JWTs (not database rows), while account and user records are persisted to PostgreSQL via the Prisma adapter. The configuration lives inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Praashh/buildml/llms.txt
Use this file to discover all available pages before exploring further.
src/server/auth/config.ts and is consumed by the Next.js API route handler and the Edge middleware.
Configuration File
The full NextAuth.js configuration is exported fromsrc/server/auth/config.ts:
src/server/auth/config.ts
Key design decisions
- JWT session strategy —
session.strategy: "jwt"means sessions are stored entirely in a signed cookie, not in aSessiontable row. TheSessionmodel in Prisma is still created by the Prisma adapter but is not the primary session mechanism. - PrismaAdapter — creates
UserandAccountrows on first sign-in; subsequent sign-ins look up the existing records. - Custom pages — the sign-in page is at
/signinand auth errors redirect to/auth/error. createUserevent — when a new user is created,emailVerifiedis set immediately tonew Date()since Google already verifies email addresses.jwtcallback — on every JWT refresh, the callback re-fetches the user’simagefrom PostgreSQL to keep the profile photo current if it changes on Google.trustHost: true— required for deployments behind a reverse proxy (e.g. Vercel) where theHostheader differs from the canonical origin.
Setting Up Google OAuth
Open Google Cloud Console
Navigate to https://console.cloud.google.com and select (or create) the project you want to use for Buildml.
Enable the Google Identity API
Go to APIs & Services → Library, search for “Google Identity” or “OAuth”, and enable the Google+ API (or the relevant identity service for your project).
Create OAuth 2.0 Credentials
Navigate to APIs & Services → Credentials → Create Credentials → OAuth 2.0 Client ID.For local development, also add:
- Application type: Web application
- Name: e.g.
Buildml - Authorised JavaScript origins: your deployment URL, e.g.
https://buildml.vercel.app - Authorised redirect URIs: append
/api/auth/callback/googleto your deployment URL:
Copy credentials to .env
After saving, Google displays a Client ID and Client Secret. Add them to your
.env file:.env
Protected Routes
Route protection is enforced by the Edge middleware insrc/middleware.ts. The middleware uses getToken from next-auth/jwt to verify the JWT cookie on every matching request — no database round-trip required.
src/middleware.ts
/signin. Expired tokens are also caught:
src/middleware.ts
| Protected path | Description |
|---|---|
/dashboard/* | User dashboard and overview pages |
/practice/* | Individual problem pages and the code editor |
/leaderboard | Global rankings page |
/profile/* | User profile and submission history |
Accessing the Session
Server-side (React Server Components, tRPC procedures, Route Handlers)
Import theauth helper from ~/server/auth and call it as an async function:
Client-side (React Client Components)
Wrap your component tree with<SessionProvider> (typically in the root layout), then use the useSession hook:
tRPC Protected Procedures
Server-side tRPC procedures that require authentication use theprotectedProcedure builder. It reads ctx.session and throws a UNAUTHORIZED TRPCError if the session is absent:
protectedProcedure from an unauthenticated client surfaces as a UNAUTHORIZED error in the tRPC response.