Skip to content

chore(supabase): config polish + lock down handle_new_user (PP-8hz) - #1309

Merged
timothyfroehlich merged 2 commits into
mainfrom
chore/supabase-config-polish
May 9, 2026
Merged

chore(supabase): config polish + lock down handle_new_user (PP-8hz)#1309
timothyfroehlich merged 2 commits into
mainfrom
chore/supabase-config-polish

Conversation

@timothyfroehlich

Copy link
Copy Markdown
Owner

Summary

  • admin.ts: Reversed URL fallback order to prefer SUPABASE_URL over NEXT_PUBLIC_SUPABASE_URL — the admin client is server-only and the server-side var should take precedence
  • env.ts: Removed the two dead non-NEXT_PUBLIC_ fallbacks (SUPABASE_PUBLISHABLE_KEY, SUPABASE_ANON_KEY) from the publishable key chain — these variables would never reach a client bundle, so the fallbacks were Vercel Marketplace migration cruft
  • rls.ts: Rewrote misleading JSDoc on withUserContext — Drizzle connects as a BYPASSRLS user so RLS is never enforced for app code; this helper exists only for integration tests that simulate RLS contexts
  • migration 0035: Hand-written REVOKE ALL ON FUNCTION public.handle_new_user() FROM anon, authenticated — defense-in-depth lockdown following the same pattern as migration 0029 (get_discord_config). The trigger function was created SECURITY DEFINER in migration 0007 but never had explicit EXECUTE revocations.

Test Plan

  • pnpm run check passes (116 test files, 1033 tests all green)
  • Updated supabase-env.test.ts to remove the now-deleted fallback paths
  • pnpm db:reset — verify migration 0035 applies and pnpm db:generate reports "No schema changes" (requires Supabase running locally; CI will exercise this via Supabase Branch Setup)

Closes PP-8hz

🤖 Generated with Claude Code

- admin.ts: prefer server-side SUPABASE_URL over NEXT_PUBLIC_SUPABASE_URL
  (admin client is server-only; SUPABASE_URL is the correct primary var)
- env.ts: remove dead non-NEXT_PUBLIC fallbacks from publishable key chain
  (SUPABASE_PUBLISHABLE_KEY and SUPABASE_ANON_KEY never reach client bundles)
- rls.ts: correct misleading JSDoc — Drizzle bypasses RLS via BYPASSRLS;
  withUserContext is for integration tests only, not app mutations
- migration 0035: REVOKE EXECUTE on public.handle_new_user() from anon and
  authenticated (defense-in-depth, mirrors pattern from migration 0029)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 9, 2026 02:33
@vercel

vercel Bot commented May 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pin-point Ready Ready Preview, Comment May 9, 2026 2:51am

@supabase

supabase Bot commented May 9, 2026

Copy link
Copy Markdown

Updates to Preview Branch (chore/supabase-config-polish) ↗︎

Deployments Status Updated
Database Sat, 09 May 2026 02:46:20 UTC
Services Sat, 09 May 2026 02:46:20 UTC
APIs Sat, 09 May 2026 02:46:20 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Sat, 09 May 2026 02:46:21 UTC
Migrations Sat, 09 May 2026 02:46:21 UTC
Seeding Sat, 09 May 2026 02:46:21 UTC
Edge Functions Sat, 09 May 2026 02:46:21 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Tightens up Supabase configuration handling and security posture by standardizing env-var precedence, clarifying RLS-related helpers’ intent, and revoking unnecessary access to a SECURITY DEFINER trigger function.

Changes:

  • Prefer server-side SUPABASE_URL for the service-role admin client; simplify getSupabaseEnv() publishable-key fallbacks to NEXT_PUBLIC_* variants only, and update unit tests accordingly.
  • Clarify withUserContext docs to reflect that Drizzle app queries bypass RLS and the helper is for test contexts.
  • Add migration 0035_lock_handle_new_user to revoke privileges on public.handle_new_user(); update Drizzle meta journal/snapshot.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/lib/supabase/admin.ts Prefers SUPABASE_URL for server-only admin client; updates missing-env error text.
src/lib/supabase/env.ts Removes non-NEXT_PUBLIC_ publishable-key fallbacks and updates missing-env error text.
src/test/unit/supabase-env.test.ts Updates env precedence tests to match the simplified key fallback chain.
src/server/db/utils/rls.ts Rewords JSDoc to clarify intended usage for integration tests and non-RLS app authorization.
drizzle/0035_lock_handle_new_user.sql Revokes privileges on the handle_new_user() trigger function (defense-in-depth).
drizzle/meta/_journal.json Records the new migration entry.
drizzle/meta/0035_snapshot.json Adds the schema snapshot for migration 0035.

Comment thread src/server/db/utils/rls.ts Outdated
Comment thread src/server/db/utils/rls.ts Outdated
Comment thread src/lib/supabase/env.ts Outdated
- rls.ts: replace NON-NEGOTIABLE #14 reference with stable file path
  (~lib/permissions/helpers); fix outdated role list to reference UserRole type
- env.ts: clarify publishable key comment — not about client bundles
  but about which env names are typically set

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review PR passed CI and has no unresolved review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants