Closed Yo-mah-Ya closed 11 months ago
@samuraikun Simply wanna ask what you think about below!
We need UUID which is unique by each user, and we wanna use it doing something which has to do with user using supabase session
.
And then I'd say the id
column in auth.users
is worth to use as above UUID. I wrote down advantages and drawbacks what I came up with as of now.
Advantages:
We don't need to generate UUID manually - insert into auth.users
and trigger insert into public.users
, but we'll just use id in auth.users
. And even more possible to have foreign key relations to enhance data correctness. There're no way that users who are not be able to be linked between auth.users
and public.users
. - not sure if it's possible though in terms of security.
Drawbacks:
We're not able to manage id column in auth.users
by ourself for sure, so this strategy partially depends on supabase.
If they change its schema by any chance, this no longer usable/reliable.
Session looks like shown below. It's on local machine.
I'd say we can use session.user.id
corresponding to id
column in auth.users
rather than session.user.user_metadata
where other meta data info coming from public.users
go to.
const session = {
access_token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNzAyOTQ5MzQ1LCJpYXQiOjE3MDI5NDU3NDUsImlzcyI6Imh0dHA6Ly8xMjcuMC4wLjE6NTQzMjEvYXV0aC92MSIsInN1YiI6IjEyZTRiMmE1LWRhYzMtNDBkZC05YmY5LTAwMjhkMzIwMmI1MSIsImVtYWlsIjoidGVzdEBnbWFpbC5jb20iLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIiwicHJvdmlkZXJzIjpbImVtYWlsIl19LCJ1c2VyX21ldGFkYXRhIjp7Im5hbWUiOiJUZXN0IE5hbWUifSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJwYXNzd29yZCIsInRpbWVzdGFtcCI6MTcwMjk0NTc0NX1dLCJzZXNzaW9uX2lkIjoiYjM4MDdiYTItNDA3MC00MGMwLTg0YWQtZTliNWViNDllNWQxIn0.hH4QdWyP3zlHDbW3789Hv2K5uMgUtszhZVFYgMMtOv4',
token_type: 'bearer',
expires_in: 3600,
expires_at: 1702949345,
refresh_token: 'h-J1sSTVHxPBzTg-xbB9hQ',
user: {
id: '12e4b2a5-dac3-40dd-9bf9-0028d3202b51',
aud: 'authenticated',
role: 'authenticated',
email: 'test@gmail.com',
email_confirmed_at: '2023-12-19T00:29:05.46772096Z',
phone: '',
last_sign_in_at: '2023-12-19T00:29:05.469634502Z',
app_metadata: { provider: 'email', providers: ['email'] },
user_metadata: { name: 'Test Name' },
identities: [
{
id: '12e4b2a5-dac3-40dd-9bf9-0028d3202b51',
user_id: '12e4b2a5-dac3-40dd-9bf9-0028d3202b51',
identity_data: {
email: 'test@gmail.com',
sub: '12e4b2a5-dac3-40dd-9bf9-0028d3202b51'
},
provider: 'email',
last_sign_in_at: '2023-12-19T00:29:05.466188294Z',
created_at: '2023-12-19T00:29:05.466203Z',
updated_at: '2023-12-19T00:29:05.466203Z'
}
],
created_at: '2023-12-19T00:29:05.459734Z',
updated_at: '2023-12-19T00:29:05.472244Z'
}
}
Thanks !
linked UUID of auth.users to public.users