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

origin url is not being set correctly

Open melodyogonna opened this issue 2 years ago • 5 comments

Environment

  • Operating System: Darwin
  • Node Version: v20.3.1
  • Nuxt Version: 3.6.1
  • Nitro Version: 2.5.2
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: css, app, devtools, typescript, build, runtimeConfig, modules, auth, hooks
  • Runtime Modules: @sidebase/[email protected]
  • Build Modules: -

Reproduction

No response

Describe the bug

I'm trying to change the default origin from http://localhost:3000 to a custom origin because I modified the port. I have tried setting NUXT_ORIGIN in an .env file as well as manually setting origin on ModuleOptions in nuxt.config.ts, none seem to work, after sign in (with the below code) I'm redirected to http://localhost:3000/user/dashboard rather than http://localhost:1200/user/dashboard (1200) is my custom port.

  await signIn('credentials', { email: form.email, password: form.password, callbackUrl: '/user/dashboard' });

Additional context

No response

Logs

No response

melodyogonna avatar Aug 01 '23 20:08 melodyogonna

you need to set the origin in nuxt.config like this:

auth: { computed: { origin: process.env.YOUR_OWN_VARIABLE, } }

Unfortunately the documentation is missing a lot of information.

radudalbea avatar Aug 02 '23 21:08 radudalbea

It got fixed by setting NEXTAUTH_URL rather than AUTH_ORIGIN

melodyogonna avatar Aug 03 '23 12:08 melodyogonna

@melodyogonna What about for prod?

autorunman22 avatar Aug 13 '23 03:08 autorunman22

@melodyogonna What about for prod?

I deployed on Vercel, and according to this - https://next-auth.js.org/warnings#nextauth_url%20-%20nuxt VERCEL_URL is automatically set so there is no reason to set NEXTAUTH_URL if you deploy on Vercel. For other environments, I imagine it is necessary but I wouldn't know.

melodyogonna avatar Aug 13 '23 09:08 melodyogonna

Hi everyone!

I will take some time to refresh our documentation! The vercel guide was originally written for V0.4, so things may have changed.

For now please manually set the NEXAUTH_URL and the origin inside your nuxt.config.ts. I however, do want to take some time code wise to clean this up and ensure that only one of the two methods is needed.

zoey-kaiser avatar Feb 23 '24 18:02 zoey-kaiser

We have just released our new documentation which improves on the explanation of how ORIGIN is used. Please have a look here: https://auth.sidebase.io/guide/advanced/deployment/self-hosted#authjs-provider

zoey-kaiser avatar Jul 13 '24 10:07 zoey-kaiser