How to acces ID token returned by oAuth provider

I'm using the Microsoft oAuth provider. It returns an ID token, which (when decoded) includes some user information I need to access, such as user group memberships. The ID token gets stored in the 'accounts' table, but I can't work out how to access it. I can't see any way using auth.api. I know I could query the database independently, but it seems like I shouldn't have to do that to access something that better-auth is storing. Any ideas?
2 Replies
Ping
Ping2d ago
Not sure if this is a valid solution, but could it be possible you can access that data in mapProfileToUser part of the oauth methods in your auth config?
Stuart B
Stuart BOPthis hour
I looked at that but it doesn't look like I can access things from the account table. Thanks for the suggestion, though. I can do it by querying the db myself and adding the data to the session object as a custom field. But I've discovered that (at least using drizzle) it already does 2 db queries each time, one for session and one for user, rather than a single joined query. If I want the idToken from the account table, that's 3 separate db queries each time a session is checked, which is excessive. I decided to go back to my Lucia auth and fix the minor issue I had. That allows me to get all the info I need with a single query.

Did you find this page helpful?