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.26k stars 162 forks source link

origin url is not being set correctly #503

Closed melodyogonna closed 2 months ago

melodyogonna commented 1 year ago

Environment

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

radudalbea commented 1 year ago

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.

melodyogonna commented 1 year ago

It got fixed by setting NEXTAUTH_URL rather than AUTH_ORIGIN

autorunman22 commented 1 year ago

@melodyogonna What about for prod?

melodyogonna commented 1 year ago

@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.

zoey-kaiser commented 7 months ago

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 commented 2 months ago

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