© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
9 replies
whiskeywizard

How to allow optional user_id foreign key for data?

Hi,

I'd like to have data that can be created by unauthenticated users, and also authenticated users.

If it's an unauth user, the user_id field would be empty. If they are authenticated, it would be forced to be the uid().

If the user_id is empty, the data can be selected by anyone - but no other actions.

If the user_id exists, then anyone can select it, but only that user can update and delete.

Any easy way to do this while sharing the same table?

Thanks.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Joining auth.user on foreign key id?
SupabaseSSupabase / help-and-questions
4y ago
Supabase Foreign Key to Identity ID instead of Auth User ID
SupabaseSSupabase / help-and-questions
13mo ago
Composite key foreign key issue
SupabaseSSupabase / help-and-questions
6mo ago
Change Display Value For Foreign Key?
SupabaseSSupabase / help-and-questions
4y ago