NuxtAuth sidebase return 404 on /session

Hello I am trying to deploy on netlify a nuxt auth using sidebase(auth.sidebase.io) but it return page not found: /session 404
the baseURL is setting to "/" even if I put the correct AUTH_ORIGIN as you can see on my nuxt.config below
auth: {
isEnabled: true,
origin: process.env.AUTH_ORIGIN || "http://localhost:3000",
disableServerSideAuth: false,
originEnvKey: "AUTH_ORIGIN",
baseURL: process.env.URL ? `${process.env.URL}/api/auth` : undefined,
provider: {
type: "authjs",
},
enableGlobalAppMiddleware: true,
},
auth: {
isEnabled: true,
origin: process.env.AUTH_ORIGIN || "http://localhost:3000",
disableServerSideAuth: false,
originEnvKey: "AUTH_ORIGIN",
baseURL: process.env.URL ? `${process.env.URL}/api/auth` : undefined,
provider: {
type: "authjs",
},
enableGlobalAppMiddleware: true,
},
I tried to show the URL env value on runtimeConfig and it show the correct info but for some reason the baseURL is changing when I deploy as you can see below console.log(runtimeConfig)
{
"public": {
"URL": "https://nuxt-auth-cs.netlify.app",
"DEPLOY_URL": "https://68cc0a3cc566ba000884265f--nuxt-auth-cs.netlify.app",
"AUTH_ORIGIN": "https://nuxt-auth-cs.netlify.app",
"secret": "your-secret-here",
"githubClientId": "Ov23liWA39hBirkhfdyl",
"githubClientSecret": "a109cf0fab4567b4673178e23333e8435eaced44",
"auth": {
"isEnabled": true,
"baseURL": "/",
"disableInternalRouting": false,
"disableServerSideAuth": false,
"originEnvKey": "AUTH_ORIGIN",
"sessionRefresh": {
"enablePeriodically": false,
"enableOnWindowFocus": true,
"handler": ""
},
"globalAppMiddleware": {
"isEnabled": false,
"allow404WithoutAuth": true,
"addDefaultCallbackUrl": true
},
"origin": "https://nuxt-auth-cs.netlify.app",
"provider": {
"type": "authjs",
"trustHost": false,
"defaultProvider": "",
"addDefaultCallbackUrl": true
},
"enableGlobalAppMiddleware": true
}
},
"app": {
"baseURL": "/",
"buildId": "128fe6ce-f5e6-4815-bd19-0a7d0f34dce0",
"buildAssetsDir": "/_nuxt/",
"cdnURL": ""
}
}
{
"public": {
"URL": "https://nuxt-auth-cs.netlify.app",
"DEPLOY_URL": "https://68cc0a3cc566ba000884265f--nuxt-auth-cs.netlify.app",
"AUTH_ORIGIN": "https://nuxt-auth-cs.netlify.app",
"secret": "your-secret-here",
"githubClientId": "Ov23liWA39hBirkhfdyl",
"githubClientSecret": "a109cf0fab4567b4673178e23333e8435eaced44",
"auth": {
"isEnabled": true,
"baseURL": "/",
"disableInternalRouting": false,
"disableServerSideAuth": false,
"originEnvKey": "AUTH_ORIGIN",
"sessionRefresh": {
"enablePeriodically": false,
"enableOnWindowFocus": true,
"handler": ""
},
"globalAppMiddleware": {
"isEnabled": false,
"allow404WithoutAuth": true,
"addDefaultCallbackUrl": true
},
"origin": "https://nuxt-auth-cs.netlify.app",
"provider": {
"type": "authjs",
"trustHost": false,
"defaultProvider": "",
"addDefaultCallbackUrl": true
},
"enableGlobalAppMiddleware": true
}
},
"app": {
"baseURL": "/",
"buildId": "128fe6ce-f5e6-4815-bd19-0a7d0f34dce0",
"buildAssetsDir": "/_nuxt/",
"cdnURL": ""
}
}
No description
3 Replies
kapa.ai
kapa.ai3mo ago
Hi @Cândido Silva. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The issue you're experiencing—Nuxt Auth (sidebase) returning a 404 on /session and the baseURL being set to "/" even when you set AUTHORIGIN and baseURL—relates to how environment variables and runtime configuration are handled in Nuxt, especially in production on platforms like Netlify. Key Points from the Knowledge Sources 1. Environment Variables in Production
In production, Nuxt does not read from your .env file. Instead, it expects environment variables to be set by the hosting platform. Only environment variables prefixed with `NUXT
will be picked up by Nuxt's runtimeConfig in production. For example, to expose a variable as runtimeConfig.public.URL, you must set NUXT_PUBLIC_URL in your environment, not just URL or AUTH_ORIGIN without the prefix. This is a common source of confusion and misconfiguration when deploying to platforms like Netlify or Vercel. [See: Runtime Config Environment Variables](<https://nuxt.com/docs/4.x/guide/going-further/runtime-config#environment-variables>), [Directory Structure: .env](<https://nuxt.com/docs/4.x/guide/directory-structure/env>) 2. **runtimeConfig and Public Variables** Only variables defined in runtimeConfig.public are available on the client side. If you want to use environment variables in your config, you should define them in runtimeConfig.public and ensure they are set with the NUXTPUBLIC prefix in your deployment environment. [See: runtimeConfig API](<https://nuxt.com/docs/4.x/api/nuxt-config#runtimeconfig-1>) 3. **baseURL and app.baseURL** The app.baseURL is a special key used by Nuxt for routing and asset loading. It can be set via the NUXT_APP_BASE_URL environment variable. If you want to change the base URL for your app (for example, if deploying to a subdirectory), you should set this variable accordingly. [See: useRuntimeConfig - app.baseURL](<https://nuxt.com/docs/4.x/api/composables/use-runtime-config#appbaseurl>) ### Why Your baseURL Might Be "/" in Production - If you set baseURL in your config using process.env.URL, but the environment variable is not prefixed with NUXTPUBLIC, Nuxt will not pick it up at runtime in production. - The runtimeConfig you logged shows "baseURL": "/" under auth, which suggests that the environment variable was not set or not picked up as expected. ### What You Should Do 1. **Set Environment Variables with the Correct Prefix** - In Netlify, set your environment variables as: - NUXT_PUBLIC_URL=https://nuxt-auth-cs.netlify.app` - NUXT_PUBLIC_AUTH_ORIGIN=<https://nuxt-auth-cs.netlify.app> - If you need to set the app base URL, use: - NUXT_APP_BASE_URL=/api/auth (or whatever your intended base is) 2. Update Your nuxt.config - Reference the environment variables using the NUXT_PUBLIC_ prefix in your runtimeConfig.public section. - Example:
export default defineNuxtConfig({
runtimeConfig: {
public: {
url: process.env.NUXT_PUBLIC_URL,
authOrigin: process.env.NUXT_PUBLIC_AUTH_ORIGIN,
// ...other public config
}
}
})

export default defineNuxtConfig({
runtimeConfig: {
public: {
url: process.env.NUXT_PUBLIC_URL,
authOrigin: process.env.NUXT_PUBLIC_AUTH_ORIGIN,
// ...other public config
}
}
})

- Then, in your auth module config, use these runtime config values. 3. Check Your Auth Module's baseURL - Make sure the baseURL is set using the correct runtime config value, not directly from process.env (which may not be available as expected in production). Summary Your 404 and baseURL issues are likely due to environment variables not being set with the required NUXT_PUBLIC_ or NUXT_APP_ prefixes in your Netlify environment. Update your environment variable names and reference them via runtimeConfig.public in your Nuxt config. This should resolve the mismatch and 404 errors you are seeing. For more details, see the official documentation on Runtime Config and Environment Variables in Production. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@781520779161894943> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Cândido Silva
Cândido SilvaOP3mo ago
IA answer did not help the problem is the baseURL inside "auth" object for the sidebase auth not the baseURL inside "app" same happens if I deploy on Vercel

Did you find this page helpful?