File size: 867 Bytes
6fc3143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- 1. Create the table if it doesn't exist
create table if not exists public.users (
  id uuid references auth.users on delete cascade not null primary key,
  email text,
  full_name text,
  avatar_url text,
  credits integer default 5,
  created_at timestamp with time zone default timezone('utc'::text, now()) not null
);

-- 2. Enable Row Level Security (RLS)
alter table public.users enable row level security;

-- 3. Create policies
-- Allow users to view their own profile
create policy "Users can view own profile" 
on public.users for select 
using (auth.uid() = id);

-- Allow users to insert their own profile
create policy "Users can insert own profile" 
on public.users for insert 
with check (auth.uid() = id);

-- Allow users to update their own profile
create policy "Users can update own profile" 
on public.users for update 
using (auth.uid() = id);