Discord OAuth redirect_uri requires double plus signs (++) prefix - Better Auth generates invalid URLs #1760

Closed
opened 2026-03-13 09:01:23 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @3eif on GitHub (Aug 22, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create Expo app with Better Auth
  2. Configure Better Auth with Discord OAuth provider

  3. Set redirect URL in Discord Developer Dashboard
  4. Add the same URL to the list of redirect URIs in Discord Developer Dashboard
  5. Attempt to authenticate using Better Auth's generated OAuth URL
  6. Observe "Invalid OAuth2 redirect_uri" errorr

  7. Compare with Discord's OAuth URL generator which adds ⁠++ prefix and works correctly

Better Auth generated URL (fails):


https://discord.com/oauth2/authorize?scope=identify+email&response_type=code&client_id=743108048892985425&redirect_uri=https://api.botsfordiscord.app/api/auth/callback/discord&state=jsk9hS34ltgAeHVS85gFZOStkVF7o_gS&prompt=none


Discord's OAuth generator URL (works):


https://discord.com/oauth2/authorize?scope=identify+email&response_type=code&client_id=743108048892985425&redirect_uri=++https://api.botsfordiscord.app/api/auth/callback/discord&state=jsk9hS34ltgAeHVS85gFZOStkVF7o_gS&prompt=none

Current vs. Expected behavior

Current behavior: Better Auth generates Discord OAuth URLs without the required ⁠++ prefix before the redirect_uri parameter, causing Discord to reject the authentication request with "Invalid OAuth2 redirect_uri" error.

Expected behavior: Better Auth should generate Discord OAuth URLs that include the ⁠++ prefix before the redirect_uri parameter to match Discord's OAuth requirements and allow successful authentication.

Evidence: Discord's own OAuth URL generator adds the ⁠++ prefix, and URLs with this prefix work correctly while Better Auth's generated URLs without the prefix fail.

What version of Better Auth are you using?

1.3.7

System info

System:
    OS: macOS 15.6.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 559.98 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 139.0.7258.139
    Safari: 18.6

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

Package

Auth config (if applicable)

// Expo side:
import { createAuthClient } from "better-auth/react";
import { expoClient } from "@better-auth/expo/client";
import * as SecureStore from "expo-secure-store";

export const authClient = createAuthClient({
  baseURL: "https://api.botsfordiscord.app",
  plugins: [
    expoClient({
      scheme: "botsfordiscord",
      storagePrefix: "botsfordiscord",
      storage: SecureStore,
    }),
  ],
});

export const { signIn, signOut, signUp, useSession } = authClient;

// API side:
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "../db/index.js";
import * as schema from "../db/schema.js";

export const auth = betterAuth({
  baseURL: "https://api.botsfordiscord.app",
  database: drizzleAdapter(db, {
    provider: "pg",
    usePlural: true,
    schema: {
      users: schema.usersTable,
      sessions: schema.sessionsTable,
      accounts: schema.accountsTable,
      verifications: schema.verificationsTable,
    },
  }),
  socialProviders: {
    discord: {
      clientId: process.env.DISCORD_CLIENT_ID as string,
      clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
      redirectURL: "https://api.botsfordiscord.app/api/auth/callback/discord",
    },
  },
  emailAndPassword: { enabled: false },
  trustedOrigins: [
    "botsfordiscord://",
    "botsfordiscord://*",
  ],
});

Additional context

No response

Originally created by @3eif on GitHub (Aug 22, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create Expo app with Better Auth 2. Configure Better Auth with Discord OAuth provider
 3. Set redirect URL in Discord Developer Dashboard 4. Add the same URL to the list of redirect URIs in Discord Developer Dashboard 5. Attempt to authenticate using Better Auth's generated OAuth URL 6. Observe "Invalid OAuth2 redirect_uri" errorr
 7. Compare with Discord's OAuth URL generator which adds ⁠++ prefix and works correctly Better Auth generated URL (fails): ``` 
https://discord.com/oauth2/authorize?scope=identify+email&response_type=code&client_id=743108048892985425&redirect_uri=https://api.botsfordiscord.app/api/auth/callback/discord&state=jsk9hS34ltgAeHVS85gFZOStkVF7o_gS&prompt=none ``` 
Discord's OAuth generator URL (works): ``` 
https://discord.com/oauth2/authorize?scope=identify+email&response_type=code&client_id=743108048892985425&redirect_uri=++https://api.botsfordiscord.app/api/auth/callback/discord&state=jsk9hS34ltgAeHVS85gFZOStkVF7o_gS&prompt=none ``` ### Current vs. Expected behavior Current behavior: Better Auth generates Discord OAuth URLs without the required ⁠++ prefix before the redirect_uri parameter, causing Discord to reject the authentication request with "Invalid OAuth2 redirect_uri" error. Expected behavior: Better Auth should generate Discord OAuth URLs that include the ⁠++ prefix before the redirect_uri parameter to match Discord's OAuth requirements and allow successful authentication. Evidence: Discord's own OAuth URL generator adds the ⁠++ prefix, and URLs with this prefix work correctly while Better Auth's generated URLs without the prefix fail. ### What version of Better Auth are you using? 1.3.7 ### System info ```bash System: OS: macOS 15.6.1 CPU: (10) arm64 Apple M2 Pro Memory: 559.98 MB / 32.00 GB Shell: 5.9 - /bin/zsh Browsers: Chrome: 139.0.7258.139 Safari: 18.6 ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript // Expo side: import { createAuthClient } from "better-auth/react"; import { expoClient } from "@better-auth/expo/client"; import * as SecureStore from "expo-secure-store"; export const authClient = createAuthClient({ baseURL: "https://api.botsfordiscord.app", plugins: [ expoClient({ scheme: "botsfordiscord", storagePrefix: "botsfordiscord", storage: SecureStore, }), ], }); export const { signIn, signOut, signUp, useSession } = authClient; // API side: import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "../db/index.js"; import * as schema from "../db/schema.js"; export const auth = betterAuth({ baseURL: "https://api.botsfordiscord.app", database: drizzleAdapter(db, { provider: "pg", usePlural: true, schema: { users: schema.usersTable, sessions: schema.sessionsTable, accounts: schema.accountsTable, verifications: schema.verificationsTable, }, }), socialProviders: { discord: { clientId: process.env.DISCORD_CLIENT_ID as string, clientSecret: process.env.DISCORD_CLIENT_SECRET as string, redirectURL: "https://api.botsfordiscord.app/api/auth/callback/discord", }, }, emailAndPassword: { enabled: false }, trustedOrigins: [ "botsfordiscord://", "botsfordiscord://*", ], }); ``` ### Additional context _No response_
GiteaMirror added the expo label 2026-03-13 09:01:23 -05:00
Author
Owner

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

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

Better Auth does not add a ++ prefix to the redirect_uri for Discord OAuth and there is no built-in support or documentation for this behavior. The code passes the redirect URI as-is from your config, so any prefix like ++ would need to be manually added if Discord requires it for your use case. You can try setting your Discord provider config like this:

socialProviders: {
  discord: {
    clientId: "...",
    clientSecret: "...",
    redirectURL: "++https://api.botsfordiscord.app/api/auth/callback/discord",
  },
}

There are no known issues, docs, or code comments in Better Auth about this Discord quirk, so if this workaround solves the problem, it may be worth flagging for maintainers to document or patch in the Discord provider logic. If you run into encoding issues, double-check how Discord expects the value to be encoded in their dashboard and in the OAuth URL.
Reference: Better Auth Discord provider code

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 (Aug 22, 2025): <!-- Greeting --> Hi @3eif! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> Better Auth does not add a `++` prefix to the `redirect_uri` for Discord OAuth and there is no built-in support or documentation for this behavior. The code passes the redirect URI as-is from your config, so any prefix like `++` would need to be manually added if Discord requires it for your use case. You can try setting your Discord provider config like this: ```js socialProviders: { discord: { clientId: "...", clientSecret: "...", redirectURL: "++https://api.botsfordiscord.app/api/auth/callback/discord", }, } ``` There are no known issues, docs, or code comments in Better Auth about this Discord quirk, so if this workaround solves the problem, it may be worth flagging for maintainers to document or patch in the Discord provider logic. If you run into encoding issues, double-check how Discord expects the value to be encoded in their dashboard and in the OAuth URL. [Reference: Better Auth Discord provider code](https://github.com/better-auth/better-auth/blob/577cfb4ab3b16d22f36892c0e843f36abcee80c3/packages/better-auth/src/social-providers/discord.ts) <!-- 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/4ad62114-0d43-4be4-975d-4a800ed09293?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/4ad62114-0d43-4be4-975d-4a800ed09293?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/4ad62114-0d43-4be4-975d-4a800ed09293?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/4ad62114-0d43-4be4-975d-4a800ed09293?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4ad62114-0d43-4be4-975d-4a800ed09293?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/4ad62114-0d43-4be4-975d-4a800ed09293?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/4ad62114-0d43-4be4-975d-4a800ed09293?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/4165)
Author
Owner

@3eif commented on GitHub (Aug 22, 2025):

@dosu I already tried doing that. Did not work.

@3eif commented on GitHub (Aug 22, 2025): [@dosu](https://go.dosu.dev/dosubot) I already tried doing that. Did not work.
Author
Owner

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

Based on the code and documentation, Better Auth does not add or expect a ++ prefix for Discord's redirect_uri, and manually adding it will just encode it as part of the URL, which Discord likely rejects as invalid. There’s no evidence that Discord officially requires a ++ prefix for OAuth, and most redirect URI issues in Expo apps are caused by mismatches in domain, scheme, or trustedOrigins config—not by missing a prefix.

Double-check that your redirect URI in Discord’s dashboard matches exactly what Better Auth generates (including encoding), and that you’re using a public domain with a valid TLD. Also, make sure your Expo app’s scheme and trustedOrigins are set up correctly on both client and backend. If you’re still seeing the error, try logging the full generated OAuth URL and compare it to Discord’s working example to spot any differences in formatting or encoding.

If Discord’s own OAuth generator is adding a ++ prefix, it may be a UI quirk or a workaround for a specific edge case, but it’s not supported by Better Auth’s provider logic and isn’t documented as a requirement. If you need to bridge a gap, consider using a proxy endpoint or custom callback handler that can adapt the redirect URI format as needed before passing it to Discord.

Let me know if you want help debugging the exact OAuth URL or config!
Better Auth Discord provider code reference

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 (Aug 22, 2025): <!-- Answer --> Based on the code and documentation, Better Auth does not add or expect a `++` prefix for Discord's `redirect_uri`, and manually adding it will just encode it as part of the URL, which Discord likely rejects as invalid. There’s no evidence that Discord officially requires a `++` prefix for OAuth, and most redirect URI issues in Expo apps are caused by mismatches in domain, scheme, or trustedOrigins config—not by missing a prefix. Double-check that your redirect URI in Discord’s dashboard matches exactly what Better Auth generates (including encoding), and that you’re using a public domain with a valid TLD. Also, make sure your Expo app’s scheme and trustedOrigins are set up correctly on both client and backend. If you’re still seeing the error, try logging the full generated OAuth URL and compare it to Discord’s working example to spot any differences in formatting or encoding. If Discord’s own OAuth generator is adding a `++` prefix, it may be a UI quirk or a workaround for a specific edge case, but it’s not supported by Better Auth’s provider logic and isn’t documented as a requirement. If you need to bridge a gap, consider using a proxy endpoint or custom callback handler that can adapt the redirect URI format as needed before passing it to Discord. Let me know if you want help debugging the exact OAuth URL or config! [Better Auth Discord provider code reference](https://github.com/better-auth/better-auth/blob/577cfb4ab3b16d22f36892c0e843f36abcee80c3/packages/better-auth/src/social-providers/discord.ts) <!-- 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/159f4ab4-59aa-45a7-8702-886dae179c9e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/159f4ab4-59aa-45a7-8702-886dae179c9e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/159f4ab4-59aa-45a7-8702-886dae179c9e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/159f4ab4-59aa-45a7-8702-886dae179c9e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/159f4ab4-59aa-45a7-8702-886dae179c9e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/159f4ab4-59aa-45a7-8702-886dae179c9e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/159f4ab4-59aa-45a7-8702-886dae179c9e?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/4165)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1760