[GH-ISSUE #1102] Question about injecting custom properties from genericOAuth profile to session #17226

Closed
opened 2026-04-15 15:15:33 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @FlurryNight on GitHub (Jan 2, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1102

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. git clone https://github.com/Bekacru/t3-app-better-auth.git
  2. implement authentication using genericOAuth to a external IdP
  3. try using mapProfileToUser to retrieve additional data for the user
  4. expect it to be on session
  5. Discover it only works paired with additionalField for database

Current vs. Expected behavior

Hello,

I'm using genericOAuth plugin to autheticate with an IdP and I'm trying to add some properties that i receive from profile and tried using mapProfileToUser, but my understanding is that when we have a database connector (in my case: sqlite), this function is to populate the fields in the database. I've tested with other field and it did that as expected.

My issue is that the current project i am using better-auth i don't need a database since is going to hit an API. I only want to store the user and respective account, and handle active sessions for the app, and the 2FA feature. But i need to have access to the additional info i get from the IdP without dealing with another db. I only need to extend the user object with them.

So it would be nice to have callbacks/hooks to inject proprieties from the provider profile upon sign in to the session/user object, and have access to them both on server and client, I've searched on the docs, but i couldn't figure if its possible now.. if I'm wrong please correct me!.

My idea is to have something like Auth.js (Session and JWT callbacks), where we can retrieve the values from the token, and pass it to session.

Thanks!, This is the best Auth library I've used so far :)

Best Regards

What version of Better Auth are you using?

1.1.8

Provide environment information

- OS [Windows 11]

Which area(s) are affected? (Select all that apply)

Package

Auth config (if applicable)

No response

Additional context

No response

Originally created by @FlurryNight on GitHub (Jan 2, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1102 ### Is this suited for github? - [X] Yes, this is suited for github ### To Reproduce 1. git clone https://github.com/Bekacru/t3-app-better-auth.git 2. implement authentication using genericOAuth to a external IdP 3. try using mapProfileToUser to retrieve additional data for the user 4. expect it to be on session 5. Discover it only works paired with additionalField for database ### Current vs. Expected behavior Hello, I'm using genericOAuth plugin to autheticate with an IdP and I'm trying to add some properties that i receive from profile and tried using mapProfileToUser, but my understanding is that when we have a database connector (in my case: sqlite), this function is to populate the fields in the database. I've tested with other field and it did that as expected. My issue is that the current project i am using better-auth i don't need a database since is going to hit an API. I only want to store the user and respective account, and handle active sessions for the app, and the 2FA feature. But i need to have access to the additional info i get from the IdP without dealing with another db. I only need to extend the user object with them. So it would be nice to have callbacks/hooks to inject proprieties from the provider profile upon sign in to the session/user object, and have access to them both on server and client, I've searched on the docs, but i couldn't figure if its possible now.. if I'm wrong please correct me!. My idea is to have something like Auth.js (Session and JWT callbacks), where we can retrieve the values from the token, and pass it to session. Thanks!, This is the best Auth library I've used so far :) Best Regards ### What version of Better Auth are you using? 1.1.8 ### Provide environment information ```bash - OS [Windows 11] ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) _No response_ ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-15 15:15:33 -05:00
Author
Owner

@arxk commented on GitHub (Jan 20, 2025):

This would be good. I'm having the same problem implementing my own custom provider. No way for me to access custom fields on my session from getUserInfo -- did you find a workaround?

<!-- gh-comment-id:2601192310 --> @arxk commented on GitHub (Jan 20, 2025): This would be good. I'm having the same problem implementing my own custom provider. No way for me to access custom fields on my session from ``getUserInfo`` -- did you find a workaround?
Author
Owner

@FlurryNight commented on GitHub (Jan 20, 2025):

This would be good. I'm having the same problem implementing my own custom provider. No way for me to access custom fields on my session from getUserInfo -- did you find a workaround?

Hi.

Unfortunately no.

I have to get the saved access token from the database meanwhile, to use it on api calls

<!-- gh-comment-id:2601288563 --> @FlurryNight commented on GitHub (Jan 20, 2025): > This would be good. I'm having the same problem implementing my own custom provider. No way for me to access custom fields on my session from ``getUserInfo`` -- did you find a workaround? Hi. Unfortunately no. I have to get the saved access token from the database meanwhile, to use it on api calls
Author
Owner

@dosubot[bot] commented on GitHub (Jun 13, 2025):

Hi, @FlurryNight. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • You are unable to inject custom properties from an external IdP profile into the session without using a database.
  • Proposed solution involves adding callbacks/hooks similar to Auth.js's Session and JWT callbacks.
  • User arxkdev also faces the same issue and inquires about a workaround.
  • You mentioned relying on accessing the saved access token from the database for API calls.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If no updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:2970840786 --> @dosubot[bot] commented on GitHub (Jun 13, 2025): Hi, @FlurryNight. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - You are unable to inject custom properties from an external IdP profile into the session without using a database. - Proposed solution involves adding callbacks/hooks similar to Auth.js's Session and JWT callbacks. - User arxkdev also faces the same issue and inquires about a workaround. - You mentioned relying on accessing the saved access token from the database for API calls. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If no updates are provided, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17226