#nuxt-auth-utils not finding env variables
3 messages · Page 1 of 1 (latest)
Based on the knowledge sources, there are a few potential issues with environment variable handling in Nuxt that might be causing your problem:
Potential Solutions
1. Use process.env in runtimeConfig
According to Nuxt 3 app deployed to Azure. Environment variables are ignored in nitro section of nuxt.config.ts, you should explicitly reference process.env variables in your nuxt.config.ts:
runtimeConfig: {
oauth: {
keycloak: {
clientId: process.env.NUXT_OAUTH_KEYCLOAK_CLIENT_ID,
realm: process.env.NUXT_OAUTH_KEYCLOAK_REALM,
serverUrl: process.env.NUXT_OAUTH_KEYCLOAK_SERVER_URL,
},
},
}
2. Check Environment Variable Naming
According to Using different api url from .env based on environment in Nuxt 3, Nuxt has specific conventions for environment variable naming. The documentation states that variables should follow the NUXT_PUBLIC_* pattern for public runtime config or match the camelCase structure of your runtimeConfig.
3. Known Issue with Nuxt 4.1.3+ and .env Files
The knowledge sources reveal a significant issue: defineNuxtConfig is not defined on nuxt 4.1.3 mentions that "Version 4.1.3 appears to have introduced two issues: the '[function] is not defined' issue and the issue with environment variables. If you use environment variables, it seems to be causing some kind of silent crash."
Since you're using Nuxt 4.2.0, this might be related. The issue was reportedly resolved in @nuxt/cli v3.29.1. Try updating your CLI version or refreshing your lockfile.
4. Verify .env File Location
As mentioned in nuxt.config.ts won't read env variables, ensure your .env file is at the root of your project and follows the standard <KEY>=<VALUE> format.