[GH-ISSUE #984] OIDC-Provider issue with redirects when signing in using the client.signIn method #8534

Closed
opened 2026-04-13 03:38:06 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @pixelmund on GitHub (Dec 21, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/984

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Set up the oidcProvider Plugin with next.js
  2. Create an account and register a oidc application
  3. I'm using postman to test the oauth flow
  4. Go through the oauth flow using the registered oidc application, make sure that you're not signed in to the provider
  5. You will be redirected to the login page, now sign in and watch the network tab
  6. It follows the redirect after login, but should instead use the frameworks router?

Current vs. Expected behavior

Currently i have to use the following to redirect to the consent page after signing in because fetch otherwise would follow the redirect.

  const searchParams = useSearchParams();
  const router = useRouter();

  async function onSubmit(values: z.infer<typeof loginSchema>) {
    try {
      await authClient.signIn.email({
        ...values,
        fetchOptions: {
          redirect: "error",
          onError(context) {
            toast.error(context.error.message);
          },
        },
      });
    } catch {
      const clientId = searchParams.get("client_id");
      const scope = searchParams.get("scope");

      if (clientId && scope) {
        router.push(`/consent?client_id=${clientId}&scope=${scope}`);
      }
    }
  }

The ideal solution would be to use the frameworks redirect or document this behaviour

What version of Better Auth are you using?

1.1.1

Provide environment information

- OS: macOS Sonoma 14.5
- Browser: Chrome

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

Backend, Client

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { oidcProvider } from "better-auth/plugins";
import { nextCookies } from "better-auth/next-js";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@/db";

export const auth = betterAuth({
  emailAndPassword: {
    enabled: true,
  },
  database: drizzleAdapter(db, {
    provider: "pg",
  }),
  plugins: [
    nextCookies(),
    oidcProvider({
      loginPage: "/sign-in",
      consentPage: "/consent",
    }),
  ],
});

Additional context

No response

Originally created by @pixelmund on GitHub (Dec 21, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/984 ### Is this suited for github? - [X] Yes, this is suited for github ### To Reproduce 1. Set up the oidcProvider Plugin with next.js 2. Create an account and register a oidc application 3. I'm using postman to test the oauth flow 4. Go through the oauth flow using the registered oidc application, make sure that you're not signed in to the provider 5. You will be redirected to the login page, now sign in and watch the network tab 6. It follows the redirect after login, but should instead use the frameworks router? ### Current vs. Expected behavior Currently i have to use the following to redirect to the consent page after signing in because fetch otherwise would follow the redirect. ```ts const searchParams = useSearchParams(); const router = useRouter(); async function onSubmit(values: z.infer<typeof loginSchema>) { try { await authClient.signIn.email({ ...values, fetchOptions: { redirect: "error", onError(context) { toast.error(context.error.message); }, }, }); } catch { const clientId = searchParams.get("client_id"); const scope = searchParams.get("scope"); if (clientId && scope) { router.push(`/consent?client_id=${clientId}&scope=${scope}`); } } } ``` The ideal solution would be to use the frameworks redirect or document this behaviour ### What version of Better Auth are you using? 1.1.1 ### Provide environment information ```bash - OS: macOS Sonoma 14.5 - Browser: Chrome ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { oidcProvider } from "better-auth/plugins"; import { nextCookies } from "better-auth/next-js"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@/db"; export const auth = betterAuth({ emailAndPassword: { enabled: true, }, database: drizzleAdapter(db, { provider: "pg", }), plugins: [ nextCookies(), oidcProvider({ loginPage: "/sign-in", consentPage: "/consent", }), ], }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 03:38:06 -05:00
Author
Owner

@IhsenBouallegue commented on GitHub (May 12, 2025):

Probably related to this issue
https://github.com/better-auth/better-auth/issues/1160

<!-- gh-comment-id:2872022661 --> @IhsenBouallegue commented on GitHub (May 12, 2025): Probably related to this issue https://github.com/better-auth/better-auth/issues/1160
Author
Owner

@BadPirate commented on GitHub (Jun 2, 2025):

Fixed by #2849 -- Issue was that authorize (oidcProvider) flow was always assuming browser call, but signIn is a fetch based call.

<!-- gh-comment-id:2931645905 --> @BadPirate commented on GitHub (Jun 2, 2025): Fixed by #2849 -- Issue was that authorize (oidcProvider) flow was always assuming browser call, but signIn is a fetch based call.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8534