Return to Application redirect issue #2193

Open
opened 2026-03-13 09:33:26 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Ritik1330 on GitHub (Oct 24, 2025).

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

When a banned user tries to log in with Google, the app redirects to the backend error page. However, the "Return to Application" button contains the backend base URL instead of the frontend base URL.

Current vs. Expected behavior

Current Behavior:
When a banned user tries to log in using Google, they are redirected to the backend error page. The “Return to Application” button contains the backend base URL instead of the frontend base URL.

Expected Behavior:
When a banned user tries to log in using Google, they should still be redirected to the error page, but the “Return to Application” button should contain the frontend base URL.

What version of Better Auth are you using?

1.3.13

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Pro",
    "release": "10.0.26200",
    "cpuCount": 8,
    "cpuModel": "Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz",
    "totalMemory": "15.88 GB",
    "freeMemory": "3.64 GB"
  },
  "node": {
    "version": "v22.20.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.3"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

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

Client

Auth config (if applicable)

import { type BetterAuthOptions, betterAuth } from "better-auth";
import { mongodbAdapter } from "better-auth/adapters/mongodb";
import { admin } from "better-auth/plugins";
import { client } from "@/db";

export const auth = betterAuth<BetterAuthOptions>({
	database: mongodbAdapter(client),
	trustedOrigins: [process.env.CORS_ORIGIN || ""],
	emailAndPassword: {
		enabled: true,
	},
	user: {
		additionalFields: {
			phoneNumber: {
				type: "string",
				required: false,
			},
		},
	},
	advanced: {
		defaultCookieAttributes: {
			sameSite: "none",
			secure: true,
			httpOnly: true,
		},
	},
	socialProviders: {
		google: {
			clientId: process.env.GOOGLE_CLIENT_ID || "",
			clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
			redirectURI: process.env.GOOGLE_REDIRECT_URI,
		},
	},
	plugins: [admin()],
});
```typescript
import { adminClient } from "better-auth/client/plugins";
import { createAuthClient } from "better-auth/react";

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


### Additional context

_No response_
Originally created by @Ritik1330 on GitHub (Oct 24, 2025). Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce When a banned user tries to log in with Google, the app redirects to the backend error page. However, the "Return to Application" button contains the backend base URL instead of the frontend base URL. ### Current vs. Expected behavior Current Behavior: When a banned user tries to log in using Google, they are redirected to the backend error page. The “Return to Application” button contains the backend base URL instead of the frontend base URL. Expected Behavior: When a banned user tries to log in using Google, they should still be redirected to the error page, but the “Return to Application” button should contain the frontend base URL. ### What version of Better Auth are you using? 1.3.13 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Pro", "release": "10.0.26200", "cpuCount": 8, "cpuModel": "Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz", "totalMemory": "15.88 GB", "freeMemory": "3.64 GB" }, "node": { "version": "v22.20.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.3" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { type BetterAuthOptions, betterAuth } from "better-auth"; import { mongodbAdapter } from "better-auth/adapters/mongodb"; import { admin } from "better-auth/plugins"; import { client } from "@/db"; export const auth = betterAuth<BetterAuthOptions>({ database: mongodbAdapter(client), trustedOrigins: [process.env.CORS_ORIGIN || ""], emailAndPassword: { enabled: true, }, user: { additionalFields: { phoneNumber: { type: "string", required: false, }, }, }, advanced: { defaultCookieAttributes: { sameSite: "none", secure: true, httpOnly: true, }, }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID || "", clientSecret: process.env.GOOGLE_CLIENT_SECRET || "", redirectURI: process.env.GOOGLE_REDIRECT_URI, }, }, plugins: [admin()], }); ```typescript import { adminClient } from "better-auth/client/plugins"; import { createAuthClient } from "better-auth/react"; export const authClient = createAuthClient({ baseURL: process.env.NEXT_PUBLIC_SERVER_URL, plugins: [adminClient()], }); ``` ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 09:33:26 -05:00
Author
Owner

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

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

To make the "Return to Application" button on the error page use your frontend base URL (instead of the backend), set the onAPIError.errorURL option in your Better Auth backend config to your frontend error page URL (e.g., https://your-frontend.com/error or http://localhost:5173/error). This ensures that, even when a banned user triggers an error during OAuth login, the redirect and button will point to your frontend, not the backend. This behavior is supported in your version and recent updates have made sure this config is respected in all error flows, including when the OAuth state is missing or consumed by the admin plugin [source 1] [source 2].

Example:

export const auth = betterAuth({
  // ...other config
  onAPIError: {
    errorURL: "http://localhost:5173/error", // or your deployed frontend error page
  },
  // ...other config
});

Make sure your frontend domain is included in trustedOrigins and always use a full absolute URL for errorURL. This will fix the redirect for the "Return to Application" button in all error scenarios.

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Oct 24, 2025): <!-- Greeting --> Hi @Ritik1330! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> To make the "Return to Application" button on the error page use your frontend base URL (instead of the backend), set the onAPIError.errorURL option in your Better Auth backend config to your frontend error page URL (e.g., https://your-frontend.com/error or http://localhost:5173/error). This ensures that, even when a banned user triggers an error during OAuth login, the redirect and button will point to your frontend, not the backend. This behavior is supported in your version and recent updates have made sure this config is respected in all error flows, including when the OAuth state is missing or consumed by the admin plugin [[source 1]](https://github.com/better-auth/better-auth/issues/4694) [[source 2]](https://github.com/better-auth/better-auth/pull/5523). Example: ```ts export const auth = betterAuth({ // ...other config onAPIError: { errorURL: "http://localhost:5173/error", // or your deployed frontend error page }, // ...other config }); ``` Make sure your frontend domain is included in trustedOrigins and always use a full absolute URL for errorURL. This will fix the redirect for the "Return to Application" button in all error scenarios. <!-- 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/3462047a-e11c-440b-a096-b3c3113b8e10?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/3462047a-e11c-440b-a096-b3c3113b8e10?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/3462047a-e11c-440b-a096-b3c3113b8e10?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/3462047a-e11c-440b-a096-b3c3113b8e10?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3462047a-e11c-440b-a096-b3c3113b8e10?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/3462047a-e11c-440b-a096-b3c3113b8e10?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3462047a-e11c-440b-a096-b3c3113b8e10?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/5541)
Author
Owner

@ping-maxwell commented on GitHub (Jan 9, 2026):

Hello can you confirm this is still an issue on the latest version of Better Auth? We've had major error page revamps past 1.4.

@ping-maxwell commented on GitHub (Jan 9, 2026): Hello can you confirm this is still an issue on the latest version of Better Auth? We've had major error page revamps past 1.4.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2193