Adding custom user fields (role, address, etc.) to auth.api.getSession()
When I call:
I get the following Drizzle Query:
Is there a way I can customize this query (in my settings or in the
auth.api.getSession
call) to include values like the role, address, subscription, etc, so that I'm able to access it from session.user
object?
I've seen the docs on customizing the session but if I use the suggested implementation I'll be hitting the database twice - once to get the default fields, and the second time to get the custom fields - and I don't want that.
Is there a way I can directly customize the query called by auth.api.getSession
so we're querying the database only once to get all of the information required?
Thanks!
Session Management | Better Auth
Better Auth session management.
1 Reply
you can potentially override it using before hook, but we don't recommend that and currently you'd be required to make an additional query.