Skip to content

fix: use service role for photo upload storage operations#46

Merged
benniemosher merged 1 commit intomainfrom
fix/upload-photo-rls-policy
Dec 6, 2025
Merged

fix: use service role for photo upload storage operations#46
benniemosher merged 1 commit intomainfrom
fix/upload-photo-rls-policy

Conversation

@benniemosher
Copy link
Copy Markdown
Contributor

Summary

  • Fix RLS policy violation when uploading disc photos
  • Use service role client for storage and database operations after verifying user authorization
  • Edge function still authenticates user and verifies disc ownership before performing privileged operations

Problem

The storage INSERT policy has a subquery checking disc ownership. When using the user's JWT token, the RLS policy chaining between storage.objects and public.discs was failing with "new row violates row-level security policy" error.

Solution

Since the edge function already:

  1. Authenticates the user via JWT
  2. Verifies the user owns the disc
  3. Checks photo count limits

We can safely use a service role client for the privileged operations (storage upload, database insert, signed URL generation).

Test plan

  • Upload photo to existing disc using camera
  • Upload photo to existing disc using library picker
  • Verify photo appears correctly after upload
  • Verify photo count limit (max 4) still works

🤖 Generated with Claude Code

The storage RLS policy was failing during photo uploads because
the EXISTS subquery checking disc ownership had issues with RLS
policy chaining. Since the edge function already verifies user
authentication and disc ownership, we use a service role client
for the privileged storage and database operations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@benniemosher benniemosher merged commit 643b84b into main Dec 6, 2025
6 checks passed
@benniemosher benniemosher deleted the fix/upload-photo-rls-policy branch December 6, 2025 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant