nuxt-auth: auth.origin setting in nuxt.config.ts is not working with next-auth@4.22

Environment

  • Operating System: Darwin
  • Node Version: v16.14.0
  • Nuxt Version: 3.2.3
  • Nitro Version: 2.2.3
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: runtimeConfig, app, vite, modules, auth, dayjs, i18n
  • Runtime Modules: @nathanchase/nuxt-dayjs-module@1.0.11, @nuxtjs/i18n@8.0.0-beta.10, @sidebase/nuxt-auth@0.5.0, formidable@3.2.5
  • Build Modules: -

Reproduction

No response

Describe the bug

After installing next-auth@4.22 and using GoogleProvider in /api/auth/[…].ts, there will be a warning message when starts up:

[next-auth][warn][NEXTAUTH_URL] https://next-auth.js.org/warnings#nextauth_url

And when using SignIn() in custom login page, Google will redirect me to the error page “redirect_uri_mismatch”. It also finds the http request to Google carries redirect_uri: http://localhost:3000/api/auth/callback/google, even the auth.origin is set in nuxt.config.ts.

Additional context

No response

Logs

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 9
  • Comments: 15 (2 by maintainers)

Most upvoted comments

@WhatzzUp I have it working on prod currently, my nuxt config is as follows:

Edit: I am using version "@sidebase/nuxt-auth": "^0.6.0-beta.3",

{
  auth: {
      isEnabled: true,
      provider: {
        type: 'authjs',
        defaultProvider: 'auth0',
      },
      globalAppMiddleware: {
        isEnabled: true,
      },
    },
}

Then in my ‘/auth/[…].ts’ I have the following:

import Auth0Provider from 'next-auth/providers/auth0';
import { NuxtAuthHandler } from '#auth';

const config = useRuntimeConfig();

export default NuxtAuthHandler({
  pages: {
    signIn: '/login',
    signOut: '/logout',
  },
  secret: config.auth0.appSecret,
  providers: [
    // @ts-expect-error You need to use .default here for it to work during SSR. May be fixed via Vite at some point
    Auth0Provider.default({
      clientId: config.public.auth0.clientId,
      clientSecret: config.auth0.clientSecret,
      issuer: config.public.auth0.domain,
      checks: 'pkce',
      authorization: {
        params: config.public.auth0.organization
          ? {
              scope: 'openid email profile offline_access',
              organization: config.public.auth0.organization,
            }
          : {
              scope: 'openid email profile offline_access',
            },
      },
    }),
  ],
});

And finally in my .env file

# NodeJS env variables
## More authentication origin (because reasons)
AUTH_ORIGIN=http://localhost:3000

## Authorization with Auth0 (https://www.auth0.com)
NUXT_PUBLIC_AUTH0_CLIENT_ID=YourClientID
NUXT_PUBLIC_AUTH0_DOMAIN=https://yourdomain.eu.auth0.com
NUXT_PUBLIC_AUTH0_ORGANIZATION=org_YoUrOrG

Hope it helps!

Same problem, if you go back to version “@sidebase/nuxt-auth”: “^0.5.0”, the problem still remains

Hey everyone!

As a quick workaround you can export NEXTAUTH_URL! Right now my time is sadly quite limited. If you just want to use the next-auth / auth.js provider I suggest to use 0.5 until 0.6 has become stable, thanks!

origin settings is also not typechecked with 0.6.0.alpha.2, something wrong with the settings defined I suppose