create table public.profile (
profile_id uuid references auth.users not null primary key,
first_name text,
last_name text,
created_at timestamp with time zone default now(),
updated_at timestamp with time zone
);
alter table public.profile
enable row level security;
create policy "Users can select their own profile." on public.profile
for select using (auth.uid() = profile_id);
create policy "Users can insert their own profile." on public.profile
for insert with check (auth.uid() = profile_id);
create policy "Users can update own profile." on public.profile
for update using (auth.uid() = profile_id);
create function public.handle_new_user()
returns trigger as $$
begin
insert into public.profile (profile_id, first_name, last_name)
values (new.id, new.raw_user_meta_data->>'first_name', new.raw_user_meta_data->>'last_name');
return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();
create table public.profile (
profile_id uuid references auth.users not null primary key,
first_name text,
last_name text,
created_at timestamp with time zone default now(),
updated_at timestamp with time zone
);
alter table public.profile
enable row level security;
create policy "Users can select their own profile." on public.profile
for select using (auth.uid() = profile_id);
create policy "Users can insert their own profile." on public.profile
for insert with check (auth.uid() = profile_id);
create policy "Users can update own profile." on public.profile
for update using (auth.uid() = profile_id);
create function public.handle_new_user()
returns trigger as $$
begin
insert into public.profile (profile_id, first_name, last_name)
values (new.id, new.raw_user_meta_data->>'first_name', new.raw_user_meta_data->>'last_name');
return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();