Hey, I've created an on_auth_user_created trigger...
# help
n
Hey, I've created an on_auth_user_created trigger using sql (not from the UI) When I create a new auth user, the trigger runs and I get "Database error updating user" TRIGGER
Copy code
drop trigger if exists on_auth_user_created on auth.users;
create trigger on_auth_user_created
    after insert
    on auth.users
    for each row
execute procedure public.handle_new_user();
Function
Copy code
create or replace function public.handle_new_user()
    returns trigger
    language plpgsql
    security definer set search_path = public
as
$$
begin
    if new.phone is null then
        insert into public.company_user (id, email, first_name, last_name)
        values (new.id, new.email, new.raw_user_meta_data ->> 'first_name', new.raw_user_meta_data ->> 'last_name');
        return new;
    else
        insert into public.personal_user (id, phone)
        values (new.id, new.phone);
        return new;
    end if;
end;
$$;
Any help would be appreciated
n
Hello @NinjaNuur! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
g
Check in the data base postgres logs right after you do a new user and see if there is any useful error information. Could be RLS error on your tables, format of columns not matching your insert data.
n
NinjaNuur (2022-04-18)
n
hey thank you for the quick response, there wasnt any useful information in the logs, also RLS is disabled as I havent gotten around to adding them yet. I also tried hardcoding the data but still got the same error, could it be something to do with permissions since I didnt create the triggers through the UI? Been stuck on this for hours so I really do appreciate your help
g
SQL editor is fine. id columns in your table is UUID does it fail for both phone and email?
n
I only tried for email, as I need to setup sms for the phone and yes my table has the following columns id: uuid, email: varchar, first_name: varchar, last_name: varchar
g
do you have both first and last name in your data input for email?
n
.signUp( { email: 'test@gmail.com', password: 'password' }, { data: { first_name: 'Mustafa', last_name: 'Nuur', }, } )
yes, this is what I done. It should work right?
g
I don't see anything obvious, but obviously there is a syntax error or data type error. If you hard coded data points, to some with with data types or syntax. I'll think about it again in an hour or two.
n
thank you 🙏
g
I really surprised no error in logs as you are getting a database error message. Did you happen to do a test and leave behind the UUID you are testing in your company table?
I did not think it mattered but you might try adding in these ->> 'first_name'::varchar as they are text type by default.... I've read they are equivalent though...
n
The issue turned out to be that the table I was pushing values to also had a trigger but that trigger had some syntax issues
It's working great now, thank you for your help!
4 Views