sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.24k stars 158 forks source link

Cannot set redirect_uri for Google authentication provider #664

Open matthewairalo opened 6 months ago

matthewairalo commented 6 months ago

Environment

Reproduction

No response

Describe the bug

I cannot set a custom redirect uri for the Google provider. It always seems to just send the default /api/auth/providers/google instead, which results in an error from Google authenticator due to redirect_uri mismatch.

Here's my configuration:

nuxt.config.js

auth: {
    provider: {
      type: 'authjs',
      token: '',
      addDefaultCallbackUrl: false,
      globalAppMiddleware: false,
    },
    addDefaultCallbackUrl: false,
    baseURL: '/nuxt-api/auth',
  },

server/routes/nuxt-api/auth/[...].ts (yes, I am trying every option that came to my mind)

  providers: [
    // @ts-ignore Import is exported on .default during SSR, so we need to call it this way. May be fixed via Vite at some point
    GoogleProvider.default({
      clientId: process.env.GOOGLE_APPID,
      options: {
        callbackUrl: `${process.env.APP_URL}/auth/callback`,
        callback_url: `${process.env.APP_URL}/auth/callback`,
        redirect_uri: `${process.env.APP_URL}/auth/callback`,
        redirectUri: `${process.env.APP_URL}/auth/callback`,
        redirect_url: `${process.env.APP_URL}/auth/callback`,
        redirectUrl: `${process.env.APP_URL}/auth/callback`,
        user: false,
      },
      callbackUrl: `${process.env.APP_URL}/auth/callback`,
      callback_url: `${process.env.APP_URL}/auth/callback`,
      redirect_uri: `${process.env.APP_URL}/auth/callback`,
      redirectUri: `${process.env.APP_URL}/auth/callback`,
      redirect_url: `${process.env.APP_URL}/auth/callback`,
      redirectUrl: `${process.env.APP_URL}/auth/callback`,
    }),
  ],

Additional context

No response

Logs

No response

matthewairalo commented 6 months ago

Similar issues with any provider. All seem to be using the default /api/auth/callback/:provider: route.

ElizeoRocha commented 6 months ago

@matthewairalo the redirect_uri worked with this approach for me, I hope it helps you

image