SupabaseS
Supabase•4y ago
so

Unable to exchange external code

Hi folks, I'm facing a similar issue as this, except with v2 API: https://github.com/supabase/supabase/discussions/1192
Attempting Discord authentication with the following:

// index.js
import { useState, useEffect } from 'react'
import { supabase } from 'utils/supabaseClient'
import Auth from 'components/Auth'
import Account from 'components/Account'

export default function Home() {
  const [session, setSession] = useState(null)

  useEffect(() => {
    supabase.auth.getSession().then(({ data: { session } }) => {
      setSession(session)
    })

    supabase.auth.onAuthStateChange((_event, session) => {
      setSession(session)
    })
  }, [])

  return (
    <div className="container" style={{ padding: '50px 0 100px 0' }}>
      {!session ? <Auth /> : <Account key={session.user.id} session={session} />}
    </div>
  )
}



// Auth.js
...
  const { user, session, error } = await supabase?.auth?.signInWithOAuth({
    provider: 'discord',
  })
...


The Discord API returns a 200 for the following request:
https://discord.com/api/v9/oauth2/authorize?client_id={REDACTED}&response_type=code&redirect_uri=https%3A%2F%{REDACTED}.supabase.co%2Fauth%2Fv1%2Fcallback&scope=email%20identify&state={REDACTED}


But the callback returns this error:
http://localhost:3000/?error=server_error&error_description=Unable+to+exchange+external+code%3A+dQ9DfLMcgFgjlU2C5VO0nRwHzZu8OM

with payload:
{
  error: server_error
  error_description: Unable to exchange external code: dQ9DfLMcgFgjlU2C5VO0nRwHzZu8OM
}
Was this page helpful?