[GH-ISSUE #1677] Social onSuccess appears to run before callback #17493

Closed
opened 2026-04-15 15:39:09 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @eastcoasting on GitHub (Mar 4, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1677

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Unless I'm missing something I think there is a broader related issue to #1631 I'm encountering—the onSuccess with social (google) sign in appears to run before the action is completed.

    const { data, error } = await signIn.social({
      fetchOptions: {
        async onSuccess(context: { data: { user: { id: string } } }) {
          console.log(context.data.user.id);
        },
      },
      provider: "google",
    });

Current vs. Expected behavior

I would have expected onSucess was a callback than ran after a successful sign in—if this is not how onSuccess is run is there another function or method that I can use? Aiming to redirect a signed in user based on conditions on a user's account after signing in, this works just fine with credentials.

What version of Better Auth are you using?

1.2

Provide environment information

Experiencing in both development and production environments.

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

Client, Backend, Documentation

Auth config (if applicable)

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "mysql",
    schema: schema,
  }),

  emailAndPassword: {
    autoSignIn: true,
    enabled: true,
  },
  socialProviders: {
    google: {
      clientId: env.GOOGLE_CLIENT_ID,
      clientSecret: env.GOOGLE_CLIENT_SECRET,
    },
  },
});

Additional context

I have tried this on both 1.0 and 1.2 releases.

Originally created by @eastcoasting on GitHub (Mar 4, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1677 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Unless I'm missing something I think there is a broader related issue to #1631 I'm encountering—the onSuccess with social (google) sign in appears to run before the action is completed. ``` const { data, error } = await signIn.social({ fetchOptions: { async onSuccess(context: { data: { user: { id: string } } }) { console.log(context.data.user.id); }, }, provider: "google", }); ``` ### Current vs. Expected behavior I would have expected onSucess was a callback than ran after a successful sign in—if this is not how onSuccess is run is there another function or method that I can use? Aiming to redirect a signed in user based on conditions on a user's account after signing in, this works just fine with credentials. ### What version of Better Auth are you using? 1.2 ### Provide environment information ```bash Experiencing in both development and production environments. ``` ### Which area(s) are affected? (Select all that apply) Client, Backend, Documentation ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "mysql", schema: schema, }), emailAndPassword: { autoSignIn: true, enabled: true, }, socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET, }, }, }); ``` ### Additional context I have tried this on both 1.0 and 1.2 releases.
GiteaMirror added the lockedbug labels 2026-04-15 15:39:09 -05:00
Author
Owner

@tb-b commented on GitHub (Apr 13, 2025):

Can confirm this is still happening

<!-- gh-comment-id:2800149008 --> @tb-b commented on GitHub (Apr 13, 2025): Can confirm this is still happening
Author
Owner

@ledihildawan commented on GitHub (Apr 25, 2025):

I feel like the sign-out is not working either, here's an example of my code:

async function signOut() {
    topBarLoader.start();

    authClient.signOut({
      fetchOptions: {
        onSuccess: () => {
          deleteRecent();

          setTimeout(() => {
            theme.setTheme("system");
          }, 400);

          eden.api["audit-log"].index.post({
            action: "sign-out",
            module: "auth",
            description: `You have successfully signed out on ${new Date().toLocaleString()} from a device with the IP ${localStorage.getItem("ip")}.`,
          });

          // router.push("/sign-in");
        },
      },
    });
  }
<!-- gh-comment-id:2829205774 --> @ledihildawan commented on GitHub (Apr 25, 2025): I feel like the sign-out is not working either, here's an example of my code: ```TS async function signOut() { topBarLoader.start(); authClient.signOut({ fetchOptions: { onSuccess: () => { deleteRecent(); setTimeout(() => { theme.setTheme("system"); }, 400); eden.api["audit-log"].index.post({ action: "sign-out", module: "auth", description: `You have successfully signed out on ${new Date().toLocaleString()} from a device with the IP ${localStorage.getItem("ip")}.`, }); // router.push("/sign-in"); }, }, }); } ```
Author
Owner

@Bekacru commented on GitHub (Jun 16, 2025):

Sorry for the late response:
onSuccess won’t be called on social sign-on since there’s a redirect — the context to call the hook is lost.

<!-- gh-comment-id:2977964292 --> @Bekacru commented on GitHub (Jun 16, 2025): Sorry for the late response: `onSuccess` won’t be called on social sign-on since there’s a redirect — the context to call the hook is lost.
Author
Owner

@eastcoasting commented on GitHub (Jun 16, 2025):

@Bekacru Is there anyway to maintain this context or accomplish this: redirect a signed in user based on conditions on a user's account after signing in, in line with with credentials.

If not this seems like a notable restriction to document with this provider. Thanks!

<!-- gh-comment-id:2978476141 --> @eastcoasting commented on GitHub (Jun 16, 2025): @Bekacru Is there anyway to maintain this context or accomplish this: redirect a signed in user based on conditions on a user's account after signing in, in line with with credentials. If not this seems like a notable restriction to document with this provider. Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17493