nuxt-auth icon indicating copy to clipboard operation
nuxt-auth copied to clipboard

Cannot set redirect_uri for Google authentication provider

Open matthewairalo opened this issue 1 year ago • 2 comments

Environment

  • Operating System: Darwin
  • Node Version: v20.10.0
  • Nuxt Version: 3.8.2
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.0
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

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 avatar Feb 12 '24 17:02 matthewairalo

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

matthewairalo avatar Feb 14 '24 09:02 matthewairalo

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

image

ElizeoRocha avatar Mar 07 '24 14:03 ElizeoRocha