[GH-ISSUE #1580] errorCallbackURL is not working it is ignored on error #8827

Closed
opened 2026-04-13 04:03:00 -05:00 by GiteaMirror · 24 comments
Owner

Originally created by @rohittiwari-dev on GitHub (Feb 26, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1580

Is this suited for github?

To Reproduce

Image

most probably this is due to callback api route and in my case code is not generated as i cancel the process to choose another account

logger do print access_denied and error_description=undefined but it do not redirect it

Current vs. Expected behavior

Current :

it is ignoring errorCallbackURL in social signing process even if it is passed and redirecting it to api default error page

expected
it should redirect to the callbackurl passed in social loging

await authClient.signIn.social(
	{
		provider: "google",
		callbackURL: "/dashboard",
		errorCallbackURL: "/sign-in",
	},
	{
		onRequest: () => {
			setIsOAuthLogin(true);
		},
		onError: (ctx) => {
			setIsOAuthLogin(false);
			toast.error(ctx.error.message);
		},
	},
);

in my case it should redirect it to signing page with queries code and description as designed

What version of Better Auth are you using?

1.1.21

Provide environment information

- OS : Windows
- Browser : Chrome

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

Client

Auth config (if applicable)

export const auth = betterAuth({
	appName: "Notespace",
	database: drizzleAdapter(db, {
		provider: "pg",
		schema: {
			...schema,
			user: schema.UserTable,
			account: schema.ConnectedAuthProvidersTable,
			session: schema.UserAuthSessionTable,
			verification: schema.UserAuthVerificationTable,
		},
	}),
	emailAndPassword: {
		enabled: true,
		autoSignIn: true,
		requireEmailVerification: true,
	},
	emailVerification: {
		sendOnSignUp: true,
		autoSignInAfterVerification: true,
		sendVerificationEmail: async ({ user, url }) => {
			await sendEmail({
				to: user.email,
				subject: "Verify your email address",
				text: `Click the link to verify your email: ${url}`,
			});
		},
	},
	socialProviders: {
		google: {
			clientId: process.env.GOOGLE_CLIENT_ID as string,
			clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
		},
	},
	plugins: [openAPI()],
} satisfies BetterAuthOptions);

Additional context

Images for reference :

Image

Image

Originally created by @rohittiwari-dev on GitHub (Feb 26, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1580 ### Is this suited for github? - [x] #1581 ### To Reproduce ![Image](https://github.com/user-attachments/assets/35165233-df4a-453c-a401-9a04b88b1cfa) most probably this is due to callback api route and in my case code is not generated as i cancel the process to choose another account logger do print access_denied and error_description=undefined but it do not redirect it ### Current vs. Expected behavior Current : it is ignoring errorCallbackURL in social signing process even if it is passed and redirecting it to api default error page expected it should redirect to the callbackurl passed in social loging ```typescript await authClient.signIn.social( { provider: "google", callbackURL: "/dashboard", errorCallbackURL: "/sign-in", }, { onRequest: () => { setIsOAuthLogin(true); }, onError: (ctx) => { setIsOAuthLogin(false); toast.error(ctx.error.message); }, }, ); ``` in my case it should redirect it to signing page with queries code and description as designed ### What version of Better Auth are you using? 1.1.21 ### Provide environment information ```bash - OS : Windows - Browser : Chrome ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript export const auth = betterAuth({ appName: "Notespace", database: drizzleAdapter(db, { provider: "pg", schema: { ...schema, user: schema.UserTable, account: schema.ConnectedAuthProvidersTable, session: schema.UserAuthSessionTable, verification: schema.UserAuthVerificationTable, }, }), emailAndPassword: { enabled: true, autoSignIn: true, requireEmailVerification: true, }, emailVerification: { sendOnSignUp: true, autoSignInAfterVerification: true, sendVerificationEmail: async ({ user, url }) => { await sendEmail({ to: user.email, subject: "Verify your email address", text: `Click the link to verify your email: ${url}`, }); }, }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, }, }, plugins: [openAPI()], } satisfies BetterAuthOptions); ``` ### Additional context Images for reference : ![Image](https://github.com/user-attachments/assets/d2f03754-f3e0-4ece-abc9-b0006a5450e3) ![Image](https://github.com/user-attachments/assets/e732b905-d567-4165-846b-d1e1315c6013)
GiteaMirror added the lockedbug labels 2026-04-13 04:03:00 -05:00
Author
Owner

@rohittiwari-dev commented on GitHub (Feb 27, 2025):

@Bekacru please help me on this its really important when it comes to maitaining a design system and neither i can modify default ui nor this feature is working

<!-- gh-comment-id:2688713465 --> @rohittiwari-dev commented on GitHub (Feb 27, 2025): @Bekacru please help me on this its really important when it comes to maitaining a design system and neither i can modify default ui nor this feature is working
Author
Owner

@rohittiwari-dev commented on GitHub (Feb 27, 2025):

Awsome thanks but when can this be released , i used better auth on production actually waiting for this fix

<!-- gh-comment-id:2688837136 --> @rohittiwari-dev commented on GitHub (Feb 27, 2025): Awsome thanks but when can this be released , i used better auth on production actually waiting for this fix
Author
Owner

@rohittiwari-dev commented on GitHub (Mar 2, 2025):

when using this

// Client Auth
import { createAuthClient } from "better-auth/react";
import { nextCookies } from "better-auth/next-js";

export const authClient = createAuthClient({
	baseURL: process.env.BETTER_AUTH_URL,
	plugins: [nextCookies()],
});

and doing social api call like

await authClient.signIn.social(
			{
				provider: "google",
				callbackURL: "/dashboard",
				errorCallbackURL: "/sign-in",
			},
			{
				onRequest: () => {
					setIsOAuthLogin(true);
				},
				onError: (ctx) => {
					setIsOAuthLogin(false);
					toast.error(ctx.error.message);
				},
			},
		);

it should redirect to errorCallbackURL right in v1.2.0

it is not redirecting
@Bekacru can you help me out

<!-- gh-comment-id:2692623039 --> @rohittiwari-dev commented on GitHub (Mar 2, 2025): when using this ```typescript // Client Auth import { createAuthClient } from "better-auth/react"; import { nextCookies } from "better-auth/next-js"; export const authClient = createAuthClient({ baseURL: process.env.BETTER_AUTH_URL, plugins: [nextCookies()], }); ``` and doing social api call like ```typescript await authClient.signIn.social( { provider: "google", callbackURL: "/dashboard", errorCallbackURL: "/sign-in", }, { onRequest: () => { setIsOAuthLogin(true); }, onError: (ctx) => { setIsOAuthLogin(false); toast.error(ctx.error.message); }, }, ); ``` it should redirect to errorCallbackURL right in v1.2.0 it is not redirecting @Bekacru can you help me out
Author
Owner

@rohittiwari-dev commented on GitHub (Mar 2, 2025):

@Bekacru ?

<!-- gh-comment-id:2692919516 --> @rohittiwari-dev commented on GitHub (Mar 2, 2025): @Bekacru ?
Author
Owner

@szilardx commented on GitHub (Apr 6, 2025):

I have this issue with 1.2.5 - setting errorCallbackURL not working using google social login.
Would it be possible to demonstrate proper usage on the nextjs demo?
Thank you!

<!-- gh-comment-id:2781706657 --> @szilardx commented on GitHub (Apr 6, 2025): I have this issue with 1.2.5 - setting errorCallbackURL not working using google social login. Would it be possible to demonstrate proper usage on the nextjs demo? Thank you!
Author
Owner

@ryuheechul commented on GitHub (Apr 16, 2025):

also experiencing errorCallbackURL being ignored on user canceling the sign in (with Google) with better-auth 1.2.7.

<!-- gh-comment-id:2808240427 --> @ryuheechul commented on GitHub (Apr 16, 2025): also experiencing `errorCallbackURL` being ignored on user canceling the sign in (with Google) with _better-auth 1.2.7_.
Author
Owner

@vinkovsky commented on GitHub (Apr 16, 2025):

same here

<!-- gh-comment-id:2809937718 --> @vinkovsky commented on GitHub (Apr 16, 2025): same here
Author
Owner

@stewones commented on GitHub (Jun 1, 2025):

same

<!-- gh-comment-id:2927830311 --> @stewones commented on GitHub (Jun 1, 2025): same
Author
Owner

@asynchroza commented on GitHub (Jun 6, 2025):

Any update here?

<!-- gh-comment-id:2949953848 --> @asynchroza commented on GitHub (Jun 6, 2025): Any update here?
Author
Owner

@asynchroza commented on GitHub (Jun 6, 2025):

After revisiting the PR which is supposedly closing this issue, I figured that the newly developed option only allows onAPIError which is a global endpoint for when the API route fails.

import {
    betterAuth
} from 'better-auth';
import { dialect } from '~/database/client';
import { env } from '~/env';

export const auth = betterAuth({
    socialProviders: {
        google: {
            clientId: env.GOOGLE_CLIENT_ID,
            clientSecret: env.GOOGLE_CLIENT_SECRET
        },
        facebook: {
            clientId: env.FACEBOOK_CLIENT_ID,
            clientSecret: env.FACEBOOK_CLIENT_SECRET
        }
    },
    database: dialect,
    onAPIError: {
        errorURL: "/login"
    }
});

This is not the preferred solution as this is a one stop solution for all flows which have authentication. In my particular case, if the user is logging in and they cancel the process, they are redirected to /login. That's fine but what if I have to reauthenticate a session in the background and something else happens? Why can't we just make the errorCallbackUrl work?

<!-- gh-comment-id:2949975743 --> @asynchroza commented on GitHub (Jun 6, 2025): After revisiting the PR which is supposedly closing this issue, I figured that the newly developed option only allows `onAPIError` which is a global endpoint for when the API route fails. ```ts import { betterAuth } from 'better-auth'; import { dialect } from '~/database/client'; import { env } from '~/env'; export const auth = betterAuth({ socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID, clientSecret: env.GOOGLE_CLIENT_SECRET }, facebook: { clientId: env.FACEBOOK_CLIENT_ID, clientSecret: env.FACEBOOK_CLIENT_SECRET } }, database: dialect, onAPIError: { errorURL: "/login" } }); ``` This is not the preferred solution as this is a one stop solution for all flows which have authentication. In my particular case, if the user is logging in and they cancel the process, they are redirected to `/login`. That's fine but what if I have to reauthenticate a session in the background and something else happens? Why can't we just make the `errorCallbackUrl` work?
Author
Owner

@H7ioo commented on GitHub (Jun 24, 2025):

Having the same issues.
When user gets banned and tries to login with OAuth, the user gets redirected to api/auth/error instead of specified redirect page

<!-- gh-comment-id:3001889536 --> @H7ioo commented on GitHub (Jun 24, 2025): Having the same issues. When user gets banned and tries to login with OAuth, the user gets redirected to api/auth/error instead of specified redirect page
Author
Owner

@irg1008 commented on GitHub (Jul 2, 2025):

In mi case the onError callback doesn't even get triggered

<!-- gh-comment-id:3028488466 --> @irg1008 commented on GitHub (Jul 2, 2025): In mi case the onError callback doesn't even get triggered
Author
Owner

@staguer commented on GitHub (Jul 2, 2025):

I'm also running into this issue.

<!-- gh-comment-id:3029386698 --> @staguer commented on GitHub (Jul 2, 2025): I'm also running into this issue.
Author
Owner

@H7ioo commented on GitHub (Jul 2, 2025):

This should be solved in the next version (1.3.0) you can check the releases page.

<!-- gh-comment-id:3029394486 --> @H7ioo commented on GitHub (Jul 2, 2025): This should be solved in the next version (1.3.0) you can check the releases page.
Author
Owner

@esoteloferry commented on GitHub (Aug 10, 2025):

Having the same issues. When user gets banned and tries to login with OAuth, the user gets redirected to api/auth/error instead of specified redirect page

I encountered same issue, and using 1.3.4 still does not fix , what workaround did you use?

<!-- gh-comment-id:3172894447 --> @esoteloferry commented on GitHub (Aug 10, 2025): > Having the same issues. When user gets banned and tries to login with OAuth, the user gets redirected to api/auth/error instead of specified redirect page I encountered same issue, and using 1.3.4 still does not fix , what workaround did you use?
Author
Owner

@erquhart commented on GitHub (Aug 14, 2025):

Confirmed this url doesn't get called if, for example, you start Google log in and hit cancel instead of approving the connection.

<!-- gh-comment-id:3186417410 --> @erquhart commented on GitHub (Aug 14, 2025): Confirmed this url doesn't get called if, for example, you start Google log in and hit cancel instead of approving the connection.
Author
Owner

@JackNeto commented on GitHub (Aug 22, 2025):

Any update on this. Not sure why this issue is closed

<!-- gh-comment-id:3215435636 --> @JackNeto commented on GitHub (Aug 22, 2025): Any update on this. Not sure why this issue is closed
Author
Owner

@najibghadri commented on GitHub (Sep 3, 2025):

Needs reopening guys.. @ping-maxwell

<!-- gh-comment-id:3250203415 --> @najibghadri commented on GitHub (Sep 3, 2025): Needs reopening guys.. @ping-maxwell
Author
Owner

@v1taly commented on GitHub (Sep 6, 2025):

Need reopening. Still doesn't work.

<!-- gh-comment-id:3261761094 --> @v1taly commented on GitHub (Sep 6, 2025): Need reopening. Still doesn't work.
Author
Owner

@buisnessvision2026 commented on GitHub (Sep 11, 2025):

still not working

<!-- gh-comment-id:3281809364 --> @buisnessvision2026 commented on GitHub (Sep 11, 2025): still not working
Author
Owner

@redsuperbat commented on GitHub (Sep 12, 2025):

I'm also facing this issue. It seems to work if I manually throw an error in a hook but not if i cancel the oauth flow by denying etc

<!-- gh-comment-id:3284377838 --> @redsuperbat commented on GitHub (Sep 12, 2025): I'm also facing this issue. It seems to work if I manually throw an error in a hook but not if i cancel the oauth flow by denying etc
Author
Owner

@erquhart commented on GitHub (Sep 12, 2025):

This issue has a lot less thumbs up reactions than comments, recommend everyone thumb it up

<!-- gh-comment-id:3286460403 --> @erquhart commented on GitHub (Sep 12, 2025): This issue has a lot less thumbs up reactions than comments, recommend everyone thumb it up
Author
Owner

@DiegoGonzalezCruz commented on GitHub (Oct 22, 2025):

this is still not working....

<!-- gh-comment-id:3433967391 --> @DiegoGonzalezCruz commented on GitHub (Oct 22, 2025): this is still not working....
Author
Owner

@Gustavonobregab commented on GitHub (Dec 1, 2025):

Any updates???? Still not working

<!-- gh-comment-id:3598059241 --> @Gustavonobregab commented on GitHub (Dec 1, 2025): Any updates???? Still not working
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8827