Creating an editable profiles table with supabase
2024-03-25There's a saying that there is no perfect product and if there ever was one supabase would be the closest to it. At least i choose to believe there is such a saying. In this article we would be going over how to implement a table to allow us save and editing user data while using the supabase authentication using triggers and functions as supabase does not allow editing the auth.users table thought the dashboard, try not to quote me on that. Anyways back to business, While trying to make a user who signs up to your application using the supabase have the ability to edit their profile with data like username, avatar, firstname, lastname or various metadata. you start by creating the profiles table and adding the id column as a foreign key relation to the auth.users table while also creating an email column to save the email address being signed up to the profiles table, which should end up looking like the image below
The next step would be creating a function and giving it whatever name you like, for this example i named my function create_profile_on_signup with a return type of trigger and a security type of definer and should look like the next two images below
And finally we have to create a trigger which i'll name on_auth_user_created on the sql editor which runs our function created earlier which can be seen in the image below
And voila you're good to go.