Hi š friends. This blog is made for teaching you how to set up triggers in supabase. You can use triggers for sending notifications or adding more rows to your tables.
šÆGoals
One day, I logged into your site and registered there. Your website allows me to add my details as Facebook does. But the problem is that you cannot add details in auth.users the table in supabase.
Relax! I will tell you what is schema and tables in Postgres(It is a database that supabase provides).
In database, there are many schemas **eg(auth, public or more). Then schemas has **tables **eg(posts, authors, comments) then tables has **rows associated with columns eg(name, created_at)
In simple diagram š
In this situation, you need to create a row in public the table so that you can fetch the userās details from supabase.
š¤Relax!!! Itās simple to implement.
First, letās setup profiles a table in your project.
Remember that we need to connect public.profile.id to auth.users.id Here, public and auth are schemas ,and profile and users are tables.
Then, you need to your functions in database settings. You can go there by clickingš
Now, click on create new functions in the top right:
Codeš
begin
insert into public.profiles(id, email)
values(new.id, new.email);
return new;
end;
Now letās go to **triggers **in database settings.
Then click on confirm.
Now, letās check it.
Boom. Now we have users in the profiles table. But thereās a bug.
When we try to delete the user from auth table. we receive
So, first, go to the profile table and delete it ā.
Then go to SQL editor
Code:
create table public.profiles(
id uuid primary key references auth.users(id) on update cascade on delete cascade,
email text not null
);
Now, you can delete the user from auth table and it will also get
deleted from profileās table.
For people who understand Hindi:
%[https://www.youtube.com/watch?v=VbfU7KRXdKM]
Top comments (0)