[GH-ISSUE #278] Support for Custom User Session Data #16829

Closed
opened 2026-04-15 14:49:30 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @mamlzy on GitHub (Oct 21, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/278

I would like to request support for adding custom user session data in better-auth, similar to the functionality offered by next-auth. This feature would allow developers to include additional user-specific information within the session object that is returned after a successful authentication.

The ability to customize session data is crucial for many use cases, such as storing roles, permissions, and other metadata directly within the session. This can simplify access to user-specific information throughout an application without the need for additional database queries or custom implementations.

It would be great if better-auth could provide a way to extend the session object either through a callback function or a similar mechanism, allowing for more flexibility in handling session data.

Thank you for your consideration, and I'm looking forward to any feedback or updates on this request!

Additional context
Example of extending the session from auth.js
image

Originally created by @mamlzy on GitHub (Oct 21, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/278 I would like to request support for adding custom user session data in `better-auth`, similar to the functionality offered by `next-auth`. This feature would allow developers to include additional user-specific information within the session object that is returned after a successful authentication. The ability to customize session data is crucial for many use cases, such as storing roles, permissions, and other metadata directly within the session. This can simplify access to user-specific information throughout an application without the need for additional database queries or custom implementations. It would be great if `better-auth` could provide a way to extend the session object either through a callback function or a similar mechanism, allowing for more flexibility in handling session data. Thank you for your consideration, and I'm looking forward to any feedback or updates on this request! **Additional context** Example of extending the session from `auth.js` ![image](https://github.com/user-attachments/assets/51d5f7a7-7154-41f2-856f-22fbcfa716ac)
GiteaMirror added the enhancementlocked labels 2026-04-15 14:49:30 -05:00
Author
Owner

@nathanielrich commented on GitHub (Oct 29, 2024):

pls add this feature, this is very important, cause so we can customize everything by our own...

<!-- gh-comment-id:2443911650 --> @nathanielrich commented on GitHub (Oct 29, 2024): pls add this feature, this is very important, cause so we can customize everything by our own...
Author
Owner

@mikeyXmomo commented on GitHub (Oct 31, 2024):

Maybe you can try this https://www.better-auth.com/docs/concepts/typescript#additional-fields

<!-- gh-comment-id:2448830456 --> @mikeyXmomo commented on GitHub (Oct 31, 2024): Maybe you can try this https://www.better-auth.com/docs/concepts/typescript#additional-fields
Author
Owner

@nathanielrich commented on GitHub (Nov 1, 2024):

Maybe you can try this https://www.better-auth.com/docs/concepts/typescript#additional-fields

The issue is that this approach would add fields to the database. Instead, we need a callback function to fetch or query additional data for the session user object as needed.

<!-- gh-comment-id:2451923139 --> @nathanielrich commented on GitHub (Nov 1, 2024): > Maybe you can try this https://www.better-auth.com/docs/concepts/typescript#additional-fields The issue is that this approach would add fields to the database. Instead, we need a callback function to fetch or query additional data for the session user object as needed.
Author
Owner

@nathanielrich commented on GitHub (Nov 5, 2024):

pls put this on the roadmap, this is an essential feature to customize the session-user for our individual needs.

<!-- gh-comment-id:2456369845 --> @nathanielrich commented on GitHub (Nov 5, 2024): pls put this on the roadmap, this is an essential feature to customize the session-user for our individual needs.
Author
Owner

@romainchkr commented on GitHub (Nov 9, 2024):

I'm looking for something similar too. It would be great in order to enable Row Level Security in a Supabase backend. Do you know if there's any way to do it without that feature ??

<!-- gh-comment-id:2466406312 --> @romainchkr commented on GitHub (Nov 9, 2024): I'm looking for something similar too. It would be great in order to enable Row Level Security in a Supabase backend. Do you know if there's any way to do it without that feature ??
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#16829