Skip to content

redirectTo option when signing in with X causes "Redirect is requested" error #41705

@Confucii

Description

@Confucii

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

In Next.js when using signInWithOAuth with the x provider and a redirectTo option, authentication fails:

const { error } = await supabase.auth.signInWithOAuth({
    provider: 'x',
    options: {
        redirectTo: `${window.location.origin}/auth/callback`,
    },
})

Error response:

{
  "errors": [
    {
      "error": "invalid_request",
      "error_description": "Redirect is requested.",
      "redirect_uri": "https://lrdewyqzapfmcpbdxfpb.supabase.co/auth/v1/callback?error=invalid_request&state="
    }
  ]
}

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create an X OAuth 2.0 app in the X Developer Portal
  2. Configure Supabase project with correct OAuth 2.0 Client ID and Client Secret
  3. Add callback URL to X app settings: https://<project-ref>.supabase.co/auth/v1/callback
  4. Install dependencies:
   {
     "@supabase/ssr": "^0.8.0",
     "@supabase/supabase-js": "^2.89.0",
     "next": "16.1.1",
     "react": "19.2.3",
     "react-dom": "19.2.3"
   }
  1. Initialize Supabase client:
   import { createClient } from '@supabase/supabase-js'
   
   const supabase = createClient(
     process.env.NEXT_PUBLIC_SUPABASE_URL!,
     process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
   )
  1. Attempt to sign in with redirectTo option:
   const { error } = await supabase.auth.signInWithOAuth({
     provider: 'x',
     options: {
       redirectTo: `${window.location.origin}/auth/callback`,
     },
   })

Expected behavior

The x provider should handle redirectTo the same way as other OAuth providers, redirecting to the specified callback URL after successful authorization.

Screenshots

Image

System information

  • OS: macOS, Windows
  • Browser (if applies) Chrome, Edge
  • Dependencies:
{
  "@supabase/ssr": "^0.8.0",
  "@supabase/supabase-js": "^2.89.0",
  "next": "16.1.1",
  "react": "19.2.3",
  "react-dom": "19.2.3"
}

Metadata

Metadata

Assignees

Labels

authAll thing Supabase Auth relatedbugSomething isn't workingexternal-issuepr-openedA PR has been opened to resolve the issueto-triage

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions