Complete the code to enable Row Level Security (RLS) on a Supabase table.
alter table messages [1] enable row level security;To activate RLS on a table, you use the ENABLE keyword with ALTER TABLE.
Complete the policy to allow users to select only their own rows.
create policy "Users can select their own messages" on messages for select using (user_id = [1]);
The function auth.uid() returns the current user's ID in Supabase, which is used to filter rows.
Fix the error in the policy condition to correctly restrict updates to the user's own rows.
create policy "Users can update their own messages" on messages for update using (user_id [1] auth.uid());
In SQL, the equality operator is a single equals sign =, not double equals.
Fill both blanks to create a policy that allows inserting messages only if the user_id matches the current user.
create policy "Users can insert their own messages" on messages for insert with check (user_id [1] [2]);
The policy checks that user_id = auth.uid() to allow inserts only by the owner.
Fill all three blanks to create a policy that allows deleting messages only if the user owns the message and the message is not older than 7 days.
create policy "Users can delete recent own messages" on messages for delete using (user_id [1] [2] and created_at > now() - interval '[3] days');
This policy ensures the user can delete only their own messages (user_id = auth.uid()) and only if the message is newer than 7 days.
