supabase icon indicating copy to clipboard operation
supabase copied to clipboard

PROD and localhost url redirects (with @nuxtjs/supabase)

Open nsina opened this issue 1 year ago • 6 comments

What's the best approach to handle both localhost and PROD environments when using OAuth? PROD currently redirects to localhost after authentication when following the supabase docs (https://supabase.com/docs/guides/auth/concepts/redirect-urls). In Supabase, the PROD url is set as Site URL, and Redirect URLs include the localhost url.

Using the @nuxtjs/supabase module, it requires a redirectTo url, and has to be the exact url for the callback page (either localhost or PROD urls).

nsina avatar Oct 24 '23 19:10 nsina

The unique workaround I found is to compose dynamically the redirect link like this:

index.vue

const user = useSupabaseUser()
const client = useSupabaseClient()

const redirectTo = `${useRuntimeConfig().public.baseUrl}/confirm`

const { data, error } = await client.auth.signInWithOAuth({
  provider: 'github',
  options: { redirectTo }
})

nuxt.config.ts

export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      baseUrl: process.env.BASE_URL || 'http://localhost:3000'
    }
  }
})

Rizzato95 avatar Oct 26 '23 07:10 Rizzato95

@Rizzato95 Thanks! How did you configure the URLs on Supabase? Site URL, and then both localhost and base url in the Redirect URLs?

nsina avatar Oct 26 '23 17:10 nsina

No, you don't need to specify your production URL twice.

Site url --> Production URL Redirect URL's --> Only localhost url

Rizzato95 avatar Oct 26 '23 17:10 Rizzato95

In our case, we generate the app once and use it under different base url (PROD, UAT, dev, ...). We can't rely on useRuntimeConfig().public.baseUrl since the runtime config is freezed as build time) So we prefer to rely on :

const redirectTo = `${useRequestURL().origin}/confirm`

PhE avatar Mar 22 '24 14:03 PhE

I ran into the same issue because I set http://localhost:3000 instead of http://localhost:3000/** in redirect URL's. So my Google OAuth will always redirect to the production URL (Site URL in Supabase). So make sure to include regex for redirect URL's.

marcaureln avatar Apr 17 '24 11:04 marcaureln

Any update on this

yacosta738 avatar Jul 27 '24 10:07 yacosta738