Environment variables
Add these to your.env.local file:
.env.local
Client factory
The codebase provides two client factories — one for the browser and one for the server. Import the appropriate one for each context.- Browser (client components)
- Server (Server Components / Route Handlers)
utils/supabase/client.ts exports a pre-built singleton using createBrowserClient from @supabase/ssr. It reads cookies automatically for SSR-compatible auth.utils/supabase/client.ts
hasSupabaseClientEnv export lets components render gracefully when env vars are absent (e.g., during CI builds).Usage in a client component
Middleware session refresh
utils/supabase/middleware.ts exports updateSession, which refreshes the Supabase auth token on every request before any server code reads the session. It is called from the root middleware.ts.
utils/supabase/middleware.ts
Admin routes (
/admin/**) and the registrations export endpoint have Cache-Control: no-store forced in the middleware response to prevent stale session data from being served by CDN or browser caches.Database tables
registrations
The primary table. Rows are inserted by the public registration form and read by the admin dashboard.
| Column | Type | Notes |
|---|---|---|
id | integer | Auto-incrementing primary key |
first_name | text | Attendee first name (letters only) |
middle_name | text | Middle name, optional |
last_name | text | Attendee last name (letters only) |
email | text | Validated email with TLD check |
mobile_number | text | National number (without country code) |
phone_country_code | text | E.164 country code (e.g. +1) |
country | text | Attendee’s country |
ghaam | text | Attendee’s ancestral village/ghaam |
mandal | text | Stored mandal value (e.g. new-jersey) |
arrival_date | date | Arrival date (ISO format) |
departure_date | date | Departure date (ISO format) |
age | integer | Attendee’s age (1–99) |
Row Level Security
RLS is enabled onpublic.registrations. The policies are:
INSERT — allow anonymous inserts
INSERT — allow anonymous inserts
The public registration form runs as the
anon role. This policy allows any unauthenticated user to insert a row, enabling public event sign-ups.SELECT — admin domain only
SELECT — admin domain only
Only authenticated users with an
@nj.sgadi.us email address can read registration data. The auth function is wrapped in a sub-select to avoid per-row evaluation:UPDATE — allow anonymous updates
UPDATE — allow anonymous updates
An
anon can update policy permits public updates (used for multi-step registration flows).SELECT — daily cron keep-alive
SELECT — daily cron keep-alive
A
daily-cron-job-read policy permits the keep-alive cron role to query the table, preventing cold-start timeouts.Google OAuth for the admin dashboard
The admin dashboard at/admin/registrations uses Google OAuth via Supabase. Only accounts with an @nj.sgadi.us email pass the RLS check after sign-in.
Enable Google provider in Supabase
Open your project in the Supabase Dashboard, go to Authentication → Providers, find Google, and enable it. You will enter the Client ID and Client Secret in a later step.
Create OAuth credentials in Google Cloud Console
- Go to Google Cloud Console and open or create a project.
- Navigate to APIs & Services → Credentials → Create Credentials → OAuth client ID.
- Choose Web application.
- Add these Authorized JavaScript origins:
http://localhost:3000https://njrajatmahotsav.com
- Add these Authorized redirect URIs:
https://your-project-id.supabase.co/auth/v1/callbackhttp://localhost:3000/auth/callbackhttps://njrajatmahotsav.com/auth/callback
- Copy the Client ID and Client Secret.
Paste credentials into Supabase
Return to Authentication → Providers → Google in the Supabase Dashboard and enter the Client ID and Client Secret you just copied. Save.
Configure redirect URL allow list
In Supabase, go to Authentication → URL Configuration and add the following to Redirect URLs:
http://localhost:3000/auth/callbackhttps://njrajatmahotsav.com/auth/callback
https://njrajatmahotsav.com (or http://localhost:3000 for local testing).Auth callback route
After Google redirects back, Supabase exchanges the OAuth code for a session via the/auth/callback route in the Next.js app. The route must be registered in both Google Cloud Console and the Supabase redirect allow list.
Troubleshooting
"Supabase is not configured" / env vars not loading
"Supabase is not configured" / env vars not loading
If you are using a git worktree,
.env.local must exist in the worktree root (where npm run dev is run), not only in the main repo. Restart the dev server after creating or changing .env.local."redirect_uri_mismatch" error from Google
"redirect_uri_mismatch" error from Google
The exact callback URL must be present in both the Google Cloud Console authorized redirect URIs and the Supabase redirect allow list. Check for trailing slashes or
http vs https mismatches.Session not persisting after sign-in
Session not persisting after sign-in
Verify that
updateSession is being called in middleware.ts and that the middleware matcher includes the /auth/callback path. Also check that cookies are not being blocked by browser settings."Invalid OAuth client" error
"Invalid OAuth client" error
The Client ID and Client Secret entered in Supabase must exactly match the values shown in Google Cloud Console for the same OAuth credential.
