fix(seed): require service role key, remove silent fallback#76
fix(seed): require service role key, remove silent fallback#76roshanraj9136 wants to merge 1 commit into
Conversation
The seed script fell back to the anon key when SUPABASE_SERVICE_ROLE_KEY was unset. With RLS restricting INSERT on courses/professors to admin, using the anon key causes confusing permission errors. Fail fast with a clear message instead.
|
@roshanraj9136 is attempting to deploy a commit to the OpenLake_Website Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe seed script now requires both ChangesSupabase Environment Variable Requirements
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lib/seed.ts (1)
6-11: 📐 Maintainability & Code Quality | 💤 Low valueRemove the misleading non-null assertion on line 6.
The
!onprocess.env.NEXT_PUBLIC_SUPABASE_URL!tells TypeScript to assume the value is defined, but line 9 immediately validates that it may be undefined. This creates an inconsistency withsupabaseServiceKey(line 7), which correctly omits the assertion since both variables undergo the same runtime check.♻️ Suggested fix for consistency
-const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!; +const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY; if (!supabaseUrl || !supabaseServiceKey) { throw new Error('NEXT_PUBLIC_SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY must be set to run seed'); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lib/seed.ts` around lines 6 - 11, Remove the misleading non-null assertion on the supabaseUrl declaration: change the const supabaseUrl assignment so it reads without the trailing "!" (i.e., use process.env.NEXT_PUBLIC_SUPABASE_URL) to match how supabaseServiceKey is declared; keep the existing runtime check that throws an Error if either supabaseUrl or supabaseServiceKey is falsy so TypeScript and runtime behavior remain consistent for the variables supabaseUrl and supabaseServiceKey.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/lib/seed.ts`:
- Around line 6-11: Remove the misleading non-null assertion on the supabaseUrl
declaration: change the const supabaseUrl assignment so it reads without the
trailing "!" (i.e., use process.env.NEXT_PUBLIC_SUPABASE_URL) to match how
supabaseServiceKey is declared; keep the existing runtime check that throws an
Error if either supabaseUrl or supabaseServiceKey is falsy so TypeScript and
runtime behavior remain consistent for the variables supabaseUrl and
supabaseServiceKey.
Problem
seed.tsline 7:If
SUPABASE_SERVICE_ROLE_KEYis unset, the script silently uses the anon key. With RLS policies restricting INSERT/UPDATE oncoursesandprofessorsto admin, seeding with the anon key fails with confusing permission errors.Fix
Throw immediately with a clear error message if the key is missing.
File changed (1)
src/lib/seed.ts— 4 lines changedSummary by CodeRabbit