SupabaseS
Supabase12mo ago
Grubse

Unable+to+exchange+external+code

Help Needed with Supabase Authentication: Discord Integration Fails to Exchange Code

We’re experiencing an issue with Supabase Authentication when integrating Discord as an OAuth provider. Here’s the background:

Current Status
  • Our application is live in both production and development environments.
  • Google Authentication is working perfectly in both environments.
Issue
  • After adding Discord as a provider, the OAuth flow does not work as expected.
  • Specifically, the code parameter in the callback redirect URL is
    null
    .
Technical Details
  • This is how we’re handling the code exchange on the server side:
  const code = url.searchParams.get('code'); // Returns null
  const { error } = await supabase.auth.exchangeCodeForSession(code);

The returned URL from Supabase looks like this:
https://ourdomain.com/login#error=server_error&error_code=unexpected_failure&error_description=Unable+to+exchange+external+code%253A+AkNWP1trHiCmeV4DhOOCpD4XBcpgEE

  • From the error, it appears Supabase is unable to exchange the external code.
What We’ve Checked
  • Redirect URIs are correctly configured in both Discord and Supabase.
  • The Discord application is set up to match the same flow as Google Authentication (client ID, client secret, scopes, etc.).
  • This issue is consistent in both development and production environments.
Questions
  • Are there any known compatibility issues or additional configurations required for Discord OAuth in Supabase?
  • What could be causing the code parameter to be null?
  • Is there a way to debug this further, or are there specific Supabase logs we should check?
We’d greatly appreciate any guidance or suggestions to resolve this!

Thanks in advance for your help.
Was this page helpful?