Getting an AUTH_NO_ORIGIN on PM2 instance
Environment
- Operating System: Linux
- Node Version: v18.19.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 am using PM2 to run the Nuxt3 build with sidebase/nuxt-auth in a production-like AWS instance. After the latest update, the app no longer runs successfully as it throws an AUTH_NO_ORIGIN error in runtime.
My .env file has it:
API_BASE_URL=https://dev.mysite.com/api
APP_URL=https://nuxt3-dev.mysite.com
AUTH_ORIGIN=https://nuxt3-dev.mysite.com
I've also tried setting it separately in nuxt.config.js, but the error seems to remain.
Additional context
No response
Logs
No response
So, I had this problem and changing the system variable to NUXT_AUTH_ORIGIN fixed the issue. This was both locally running Windows 11, but also in Kubernetes stack with an Ubuntu guest.
I use set -a && source .env && set +a in the project directory to export env variables and then use pm2 start ecosystem.config.cjs to start.
In case of updates
# Load env variables
set -a && source .env && set +a
# Restart the application
pm2 restart EXAMPLE.com --update-env
@tberk - your solution helped. thank you! I'm leaving this as an open issue because the library should look for .env variables defined on the application level.
@matthewairalo nuxt itself doesn't read .env files in production either if that's what you're suggesting
Yes, I believe this issue isn't with the library itself but rather relates to how Nuxt manages environment variables.
From the Nuxt 3 documentation: https://nuxt.com/docs/guide/directory-structure/env
After your server is built, you are responsible for setting environment variables when you run the server. Your .env file will not be read at this point. How you do this is different for every environment.
I answered here, you can view it here. I answered here, you can view it here.
- I set the
baseURLinstead oforiginin auth option on nuxt.config.ts - setup
AUTH_ORIGIN=http://localhost:3000in .env - setup
NEXTAUTH_SECRET=<key>in .env - setup
process.env.NEXTAUTH_SECRETinNuxtAuthHandler's againstsecretkey development run is ok, but while running the build, getting the error
nuxt] [request error] [unhandled] [500] AUTH_NO_SECRET: No `secret` - this is an error in production, see https://sidebase.io/nuxt-auth/resources/errors. You can ignore this during development
at NuxtAuthHandler (./.output/server/chunks/_..._.mjs:40:13)
at ./.output/server/chunks/_..._.mjs:134:15
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async Object.handler (./.output/server/chunks/nitro/node-server.mjs:3078:19)
at async Server.toNodeHandle (./.output/server/chunks/nitro/node-server.mjs:3267:7)