Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation refers to wrong environment variable for AUTH_NO_ORIGIN error #906

Closed
ronaldtb opened this issue Sep 11, 2024 · 3 comments · Fixed by #908
Closed

Documentation refers to wrong environment variable for AUTH_NO_ORIGIN error #906

ronaldtb opened this issue Sep 11, 2024 · 3 comments · Fixed by #908
Labels
bug A bug that needs to be resolved p1 Low priority

Comments

@ronaldtb
Copy link

Environment

not applicable

Reproduction

Start Nuxt using the NUXT_AUTH_ORIGIN value set in production.
The Error: AUTH_NO_ORIGIN: No origin - this is an error in production error will be thrown.

Describe the bug

The documentation at https://auth.sidebase.io/resources/error-reference#auth-no-origin refers to the NUXT_AUTH_ORIGIN environment variable, but according to https://github.com/sidebase/nuxt-auth/blob/main/docs/guide/application-side/configuration.md?plain=1#L11 the environment variable needs to be AUTH_ORIGIN.

Changing the environment variable to AUTH_ORIGIN works with version 0.9.2.

Additional context

No response

Logs

No response

@ronaldtb ronaldtb added bug A bug that needs to be resolved pending An issue waiting for triage labels Sep 11, 2024
@ronaldtb ronaldtb changed the title Documentations refers to wrong environment variable for AUTH_NO_ORIGIN Documentation refers to wrong environment variable for AUTH_NO_ORIGIN error Sep 11, 2024
@phoenix-ru
Copy link
Collaborator

Both these env variables are interchangeable. Prior to 0.9 we asked you to set AUTH_ORIGIN, but after #837 and #848 it is now possible to also set NUXT_AUTH_ORIGIN which would also be attached to runtimeConfig by Nuxt.

See code responsible for it:

Extracting from runtimeConfig

function extractFromRuntimeConfig(config: RuntimeConfig, envVariableName: string): string | undefined {
let normalized = envVariableName.startsWith('NUXT_')
? envVariableName.slice(5)
: envVariableName
normalized = camelCase(normalized, { normalize: true })
const extracted = config[normalized]
return typeof extracted === 'string'
? extracted
: undefined
}

From process.env:

const envOrigin = envFromRuntimeConfig ?? process.env[envOriginKey]

@phoenix-ru phoenix-ru closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2024
@phoenix-ru phoenix-ru added question A question about NuxtAuth and removed bug A bug that needs to be resolved pending An issue waiting for triage labels Sep 12, 2024
@phoenix-ru
Copy link
Collaborator

phoenix-ru commented Sep 12, 2024

Reopening after some consideration as it's apparently a legitimate bug. Nuxt filters out environment variables which are not defined on runtimeConfig. See "key requirements" here: https://nuxt.com/docs/guide/going-further/runtime-config#environment-variables


edit: you can fix it by including

runtimeConfig: {
  authOrigin: ''
}

to your nuxt.config.ts - this should tell Nuxt it can use NUXT_AUTH_ORIGIN safely in prod

@phoenix-ru phoenix-ru reopened this Sep 12, 2024
@phoenix-ru phoenix-ru added p1 Low priority bug A bug that needs to be resolved and removed question A question about NuxtAuth labels Sep 12, 2024
@dingdangdog
Copy link

I thought originEnvKey was an optional config, but it looks like it's required even when using the runtimeconfig.authOrigin environment variable, I must use originEnvKey: "NUXT_AUTH_ORIGIN" to avoid errors ! ! !

Now it seems that my code is not wrong, but it took me a long time, so I record it here.

Am I missing something? Can anyone tell me what's going on?

my config

@sidebase/nuxt-auth:^0.10.0
node version: v20.12.0
npm version: 9.8.1

  • package.json
{
  "name": "modulename",
  "private": true,
  "type": "module",
  "license": "MIT",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev --host 0.0.0.0",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "dependencies": {
    "@mdi/font": "^7.4.47",
    "@nuxtjs/i18n": "^8.3.1",
    "@nuxtjs/tailwindcss": "^6.12.2",
    "@prisma/client": "^6.2.1",
    "@prisma/nuxt": "^0.2.0",
    "@sidebase/nuxt-auth": "^0.10.0",
    "echarts": "^5.6.0",
    "next-auth": "~4.21.1",
    "nuxt": "^3.12.4",
    "nuxt-echarts": "^0.2.4",
    "vue": "latest",
    "vuetify-nuxt-module": "^0.18.3",
    "xlsx": "^0.18.5"
  }
}
  • nuxt.config.ts
  runtimeConfig: {
    public: {},
    appVersion: "",
    appUrl: "",
    dataPath: "",
    authSecret: "",
    authOrigin: "", // NUXT_AUTH_ORIGIN
  },

  modules: [
    "@nuxtjs/i18n",
    "vuetify-nuxt-module",
    "@nuxtjs/tailwindcss",
    "nuxt-echarts",
    "@sidebase/nuxt-auth",
    "@prisma/nuxt",
  ],

  auth: {
    // baseURL: process.env.NUXT_AUTH_ORIGIN,
    // globalAppMiddleware: false,
    // originEnvKey: "NUXT_AUTH_ORIGIN",
    provider: {
      type: "authjs",
      trustHost: false,
      addDefaultCallbackUrl: true,
    },
    sessionRefresh: {
      enablePeriodically: false,
      enableOnWindowFocus: true,
    },
  },
  • .env
NUXT_AUTH_ORIGIN="http://localhost:9090/api/auth"

Based on the above configuration, running npm run dev will still prompt:

ℹ AUTH_NO_ORIGIN: No origin - this is an error in production, see https://sidebase.io/nuxt-auth/resources/errors. You can ignore this during development

This error is so annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug that needs to be resolved p1 Low priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants