Database error saving new user when using trigger w/ public.users table
See original GitHub issueBug report
Describe the bug
I created a public.users table, with id (uuid) and email (varchar) fields, and set up the trigger as mentioned here. This results in being unable to create a user through “Authentication > Invite New User”, and through a web app using supabase.auth.signIn({ provider: "google" })
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Create new project
- Add public
userstable with id: uuid, and email: varchar - Execute the following SQL
CREATE OR REPLACE FUNCTION signup_copy_to_users_table()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO public.users (id, email)
VALUES(new.id, new.email);
RETURN NEW;
END;
$$
LANGUAGE plpgsql SECURITY DEFINER;
DROP TRIGGER IF EXISTS signup_copy on auth.users;
CREATE TRIGGER signup_copy
AFTER INSERT ON auth.users
FOR EACH ROW EXECUTE PROCEDURE signup_copy_to_users_table();
- At this point, you will be unable to invite a user through the Authentication UI
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:22 (4 by maintainers)
Top Results From Across the Web
Database Error Saving New User error with Postgres Function?
I have created a trigger and function that would, upon insertion of a new row in auth.users , will insert a row into...
Read more >Managing User Data - Supabase
If you want to add a row to your public.profiles table every time a user signs up, you can use triggers. If the...
Read more >Getting this error on the trigger : r/Supabase - Reddit
Hi team I want to insert a record in a table sitting in public schema based on the record creation in auth.users table....
Read more >Use Supabase to Subscribe to Database Events with Postgres ...
In this video, we implement a Postgres trigger to listen to INSERT events on the auth. users table and call our create_profile_for_user function....
Read more >sql server - Trigger to restrict users from creating a new table ...
If you really must use a trigger you can use a database trigger. CREATE TRIGGER NoCreateTable ON DATABASE FOR CREATE_TABLE AS PRINT 'You...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Hashnode Post
No results found
Hi all - I just tried with a new project and didn’t have any errors here. Here were the steps:
Let me know if I’m missing anything
Hey, i’ve had the same issue and this works for me, thanks. It seems that the SQL function and trigger only works if the users table is created in pure SQL not via supabase Dashboard. Should we update the documentation to avoid any other lost adventurers like us ?