https://supabase.com/ logo
Is it possible to get a user_id from a discord user?
a

auser

05/25/2023, 1:05 AM
I have a site with discord social auth enabled, but I need to get the referenced user_id (from
auth.users
via
auth.identities
), is it possible to get the user_id? Help
n

NanoBit

05/25/2023, 1:54 AM
Perhaps, you can create a trigger on_user_create to insert into public.profile with user_id | discord_id
a

auser

05/25/2023, 2:05 AM
Hm, I figured
Thanks
Wait, how would I get the discord id from the new user event though?
n

NanoBit

05/25/2023, 2:07 AM
Where is discord id stored?
You can have a ON INSERT and UPDATE trigger that checks for the discord_id and populate that field within the
public.profile
table if it exists
a

auser

05/25/2023, 2:08 AM
I'm just using the
signinwithOauth()
function
so it's in the
auth.identities
table
n

NanoBit

05/25/2023, 2:10 AM
you can add the trigger ON that table then right?
I don't use social auth, but the process should work
a

auser

05/25/2023, 2:11 AM
good question
lemme try that
hm, no good on
new.raw_user_meta_data
at least
idk where to get the id
n

NanoBit

05/25/2023, 2:21 AM
could you check this table?
g

garyaustin

05/25/2023, 2:26 AM
Use
raise log 'my value = %',new;
in your trigger function and look in postgres logs to see all the values. But it would be whatever column name it is in for that table new.colname. I don't use OAuth either so not sure where it goes to. Some info like the OAuth access token are not stored at all for security reasons. I don't think that table has raw_user_meta_data like auth.users.
Looking at that table it almost has to be under the column identity_data if it is there.
a

auser

05/25/2023, 2:35 AM
good idea, thank you
Where umm... exactly are the logs?
g

garyaustin

05/25/2023, 2:41 AM

https://cdn.discordapp.com/attachments/1111097762247884852/1111121874424971314/image.png

a

auser

05/25/2023, 2:42 AM
thanks -- I'm on local for dev, but I guess I'll just have to push
g

garyaustin

05/25/2023, 2:57 AM
Yeah, it is there, but I don't do local either. It is in the file system somewhere. But if your trigger is on that table the new.xxx means .xxx is a column name in that table.