[GH-ISSUE #3149] Extending the ctx object in the fetch options #9492

Closed
opened 2026-04-13 04:58:33 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Frost7994 on GitHub (Jun 23, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3149

Is this suited for github?

  • Yes, this is suited for github

I would like to be able to extend the data returned in the context object in the fetch options of the sign in methods. If additional fields are added to a table you can infer them to be returned by the useSession but I need access in some of the auth methods.

Describe the solution you'd like

Currently I am calling signIn.email as follows:

await signIn.email(
{
email,
password,
},
{
onError: (ctx) => {
toast(ctx.error.message);
},

      onSuccess: () => {
        toast("Sign in successful! Redirecting ...");

        router.push(`/${ROLE}/u/${USERNAME}`);
      },
    }
  );

The ROLE and USERNAME are hardcoded constants. What I'd like is that to be returned in ctx to be dynamic such as:

await signIn.email(
{
email,
password,
},
{
onError: (ctx) => {
toast(ctx.error.message);
},

      onSuccess: (ctx) => {
        toast("Sign in successful! Redirecting ...");

        router.push(`/${ctx.data.user.role}/u/${ctx.data.user.username}`);
      },
    }
  );

Describe alternatives you've considered

I've checked the docs for a solution or some way to infer the fields to no avail.

Additional context

No response

Originally created by @Frost7994 on GitHub (Jun 23, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3149 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I would like to be able to extend the data returned in the context object in the fetch options of the sign in methods. If additional fields are added to a table you can infer them to be returned by the useSession but I need access in some of the auth methods. ### Describe the solution you'd like Currently I am calling signIn.email as follows: await signIn.email( { email, password, }, { onError: (ctx) => { toast(ctx.error.message); }, onSuccess: () => { toast("Sign in successful! Redirecting ..."); router.push(`/${ROLE}/u/${USERNAME}`); }, } ); The ROLE and USERNAME are hardcoded constants. What I'd like is that to be returned in ctx to be dynamic such as: await signIn.email( { email, password, }, { onError: (ctx) => { toast(ctx.error.message); }, onSuccess: (ctx) => { toast("Sign in successful! Redirecting ..."); router.push(`/${ctx.data.user.role}/u/${ctx.data.user.username}`); }, } ); ### Describe alternatives you've considered I've checked the docs for a solution or some way to infer the fields to no avail. ### Additional context _No response_
GiteaMirror added the enhancementlocked labels 2026-04-13 04:58:33 -05:00
Author
Owner

@Coded-by-MJ commented on GitHub (Aug 18, 2025):

@Frost7994 did you get a solution to your issue?
I'm trying to get the properties defined on the auth config additional Fields why signing in the user.

<!-- gh-comment-id:3196018518 --> @Coded-by-MJ commented on GitHub (Aug 18, 2025): @Frost7994 did you get a solution to your issue? I'm trying to get the properties defined on the auth config additional Fields why signing in the user.
Author
Owner

@dosubot[bot] commented on GitHub (Nov 17, 2025):

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

Issue Summary:

  • You requested the ability to extend the context object in sign-in fetch options to dynamically access additional user fields like role and username during authentication callbacks.
  • Currently, these fields are hardcoded and not included in ctx.data for use in onSuccess and onError handlers.
  • You noted that the documentation does not provide a solution for this customization.
  • Another user, Coded-by-MJ, expressed interest in this feature and asked if you found a solution.
  • The issue remains unresolved with no further updates or workarounds provided.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3542706251 --> @dosubot[bot] commented on GitHub (Nov 17, 2025): Hi, @Frost7994. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested the ability to extend the context object in sign-in fetch options to dynamically access additional user fields like role and username during authentication callbacks. - Currently, these fields are hardcoded and not included in `ctx.data` for use in `onSuccess` and `onError` handlers. - You noted that the documentation does not provide a solution for this customization. - Another user, Coded-by-MJ, expressed interest in this feature and asked if you found a solution. - The issue remains unresolved with no further updates or workarounds provided. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here. - If I do not hear back within 7 days, I will automatically close this issue. 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#9492