In Supabase, when you use auth.uid() inside a Row Level Security (RLS) policy, what does it represent?
Think about who the policy needs to check permissions for during a request.
auth.uid() returns the unique ID of the user currently logged in and making the request. This allows policies to restrict access based on the user's identity.
Given a table tasks with a column owner_id, which policy condition correctly allows users to SELECT only their own tasks using auth.uid()?
Think about how to match the task owner with the current user.
The condition owner_id = auth.uid() ensures that only tasks owned by the logged-in user are accessible.
You want to create an UPDATE policy on a profiles table so users can only update their own profile. Which policy condition correctly enforces this using auth.uid()?
Remember the correct syntax for comparing columns and functions in SQL.
The condition user_id = auth.uid() correctly compares the user_id column to the current user's ID, allowing updates only on their own profile.
You have a documents table with columns owner_id and is_public. You want a SELECT policy that allows users to see their own documents or any document marked as public. Which condition correctly implements this using auth.uid()?
Think about allowing access if either condition is true.
The condition owner_id = auth.uid() OR is_public = true allows users to see documents they own or any document that is public.
When creating an INSERT policy on a comments table that has a user_id column, what is the best practice to ensure users can only insert comments as themselves using auth.uid()?
Think about how to prevent users from inserting comments as other users.
By requiring user_id = auth.uid() in the INSERT policy, you ensure users can only insert comments attributed to themselves, preventing impersonation.
