Differentiate Sessions And Users Based On Multiple Social Providers
Hi! I am currently working on a solution to tie sessions to an account rather than the user, I was wondering if there is already an existing implementation or would I have to modify the Core Schema of Better-Auth?
Note: I see this pull request has been merged for
better-auth
v1.2.8-beta.1, would it be applicable to my scenario?
Versions
- better-auth
v1.2.7
- @tanstack/react-start
v1.116.1
Description
Authenticating via social provider leads to 1 record in the users
table and 1 record in the accounts
table being created.
The issue is when the user logs in with another social provider that uses the same email as their previous login, no new user record is created since the email
column has a unique constraint but a new account is created.
Since the sessions
table is tied to the users
table, it will use the previously saved user image
and the session itself cannot tell which account they are logged in as.
Question
How would I tell what account I am logged in as based on the current session rather than the user that is logged in?
So far I have attempted to read the context in my beforeCreate hook for sessions after passing the provider_id
via the beforeCreateAuthMiddleware hook but the context is null
in this scope.
Thanks in advance!
0 Replies