-
Notifications
You must be signed in to change notification settings - Fork 4
/
SUPABASE.sql
39 lines (36 loc) · 879 Bytes
/
SUPABASE.sql
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
30
31
32
33
34
35
36
37
38
39
-- inserts a row into public."user"
create function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = public
as $$
begin
insert into public."user" (
id,
"name",
"email",
"user_id"
)
values (
new.id,
new.raw_user_meta_data->>'name',
new."email",
new.id
);
return new;
end;
$$;
-- trigger the function every time a user is created
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();
-- Security
-- By default, supabase exposes the public schema but since we route through nextjs/trpc we don't need to do this
-- This also makes it so we don't need row-level security (RLS)
REVOKE USAGE ON SCHEMA public FROM anon, authenticated;
-- View for Prisma
create or replace view auth_users as
select
*
from
auth.users