[GH-ISSUE #4197] Async mapProfileToUser functions silently drop mapped fields in OAuth callback #27183

Closed
opened 2026-04-17 18:02:20 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @kyrregjerstad on GitHub (Aug 24, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4197

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Configure OAuth provider with an async mapProfileToUser function:
mapProfileToUser: async (profile) => {
  const data = await fetchSomething();
  return { ...profile, customField: data.value };
}
  1. Complete OAuth authentication flow
  2. Check databaseHooks.user.create.before - mapped fields are missing

Current vs. Expected behavior

Async mapProfileToUser functions are accepted but silently drop all mapped fields. The core OAuth callback merges results without awaiting, causing the Promise object to be spread (no-op) instead of the actual mapped data.

Expected: Either reject async functions with a clear error, or properly await the result. Fields should reach database hooks as intended.

Impact: Silent data loss with no error messages, making this extremely difficult to debug without source code knowledge.

What version of Better Auth are you using?

1.3.7

System info

-

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

Types

Auth config (if applicable)


Additional context

suggested fix implemented in: https://github.com/better-auth/better-auth/pull/4196

Originally created by @kyrregjerstad on GitHub (Aug 24, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4197 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Configure OAuth provider with an async mapProfileToUser function: ```ts mapProfileToUser: async (profile) => { const data = await fetchSomething(); return { ...profile, customField: data.value }; } ``` 2. Complete OAuth authentication flow 3. Check databaseHooks.user.create.before - mapped fields are missing ### Current vs. Expected behavior Async `mapProfileToUser` functions are accepted but silently drop all mapped fields. The core OAuth callback merges results without awaiting, causing the Promise object to be spread (no-op) instead of the actual mapped data. **Expected:** Either reject async functions with a clear error, or properly await the result. Fields should reach database hooks as intended. **Impact:** Silent data loss with no error messages, making this extremely difficult to debug without source code knowledge. ### What version of Better Auth are you using? 1.3.7 ### System info ```bash - ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript ``` ### Additional context suggested fix implemented in: https://github.com/better-auth/better-auth/pull/4196
GiteaMirror added the locked label 2026-04-17 18:02:20 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 24, 2025):

Hi @kyrregjerstad! I'm Dosu and I’m helping the better-auth team.

In Better Auth v1.3.7, the OAuth callback flow does properly await async mapProfileToUser functions before merging their results, so mapped fields should not be silently dropped if the function is implemented as expected. The relevant code awaits the function and then spreads the resolved object into the user data, supporting both sync and async signatures as shown in the type definitions and implementation (see code).

There is no evidence that PR #4196 exists or has been merged, and no documentation or issues were found describing a fix or warning for this scenario. If you are still seeing mapped fields missing, it may be worth double-checking your implementation or providing a minimal reproducible example, as the current codebase should support async mapProfileToUser functions as intended.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3218007027 --> @dosubot[bot] commented on GitHub (Aug 24, 2025): <!-- Greeting --> Hi @kyrregjerstad! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> In Better Auth v1.3.7, the OAuth callback flow does properly await async mapProfileToUser functions before merging their results, so mapped fields should not be silently dropped if the function is implemented as expected. The relevant code awaits the function and then spreads the resolved object into the user data, supporting both sync and async signatures as shown in the type definitions and implementation [(see code)](https://github.com/better-auth/better-auth/blob/8c23eb07396478a51b4dc7de669c010cdadc5479/packages/better-auth/src/plugins/generic-oauth/index.ts). There is no evidence that PR #4196 exists or has been merged, and no documentation or issues were found describing a fix or warning for this scenario. If you are still seeing mapped fields missing, it may be worth double-checking your implementation or providing a minimal reproducible example, as the current codebase should support async mapProfileToUser functions as intended. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/51e0dafd-c275-4763-8aa2-c1bcae565e33?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/51e0dafd-c275-4763-8aa2-c1bcae565e33?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/51e0dafd-c275-4763-8aa2-c1bcae565e33?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/51e0dafd-c275-4763-8aa2-c1bcae565e33?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/51e0dafd-c275-4763-8aa2-c1bcae565e33?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/51e0dafd-c275-4763-8aa2-c1bcae565e33?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/51e0dafd-c275-4763-8aa2-c1bcae565e33?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4197)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27183