Attempting to deploy a nuxt application on a server with nginx acting as a proxy to localhost. Everything seems to be functioning properly; the application can be accessed using the server's domain and API calls can be made to the server. However, authentication is not working as expected. The error displayed in the image occurs when attempting to log in a user.
Error in the browser's console after an attempted authentication
To run the server, pm2 is used with the ecosystem.config.cjs file:
module.exports = {
apps: [
{
name: 'eurocore-coopetition',
port: '3000',
exec_mode: 'cluster',
instances: '1',
script: './.output/server/index.mjs'
}
]
}
This is the nuxt.config.ts file configuration:
// https://nuxt.com/docs/api/configuration/nuxt-config
import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
export default defineNuxtConfig({
devtools: { enabled: true },
build: {
transpile: ['vuetify'],
},
modules: [
(_options, nuxt) => {
nuxt.hooks.hook('vite:extendConfig', (config) => {
// @ts-expect-error
config.plugins.push(vuetify({ autoImport: true }))
})
},
'@sidebase/nuxt-auth'
//...
],
vite: {
vue: {
template: {
transformAssetUrls,
},
},
},
css: [
'/assets/custom-theme.scss',
],
auth: {
baseURL: process.env.NUXT_AUTH_ORIGIN,
globalAppMiddleware: true
},
runtimeConfig: {
authSecret: process.env.NUXT_AUTH_SECRET,
registrationCode: process.env.NUXT_REGISTRATION_CODE,
},
})
The auth origin is set to http://localhost:3000/
.
This is the [...].ts file located in /server/api/auth
:
import bcrypt from "bcrypt";
import { NuxtAuthHandler } from "#auth"
import { PrismaClient } from "@prisma/client"
import { PrismaAdapter } from "@next-auth/prisma-adapter"
import CredentialsProvider from "next-auth/providers/credentials"
const config = useRuntimeConfig();
const prisma = new PrismaClient()
declare module "next-auth"{
interface User {
role: string
}
}
... (remaining content unchanged for brevity)
<p>Tried changing the baseURL to the server's domain but that resulted in pages not loading. In development mode everything works fine, and deploying locally via pm2 also works. Unsure of the current issue.</p>
<p>Update!
Deployed another nuxt project with the same authentication setup, yet the issue persists. Below is the nginx configuration file. Managed to successfully deploy the project on Vercel. Suspect the problem lies within the baseURL, although multiple changes to environmental variables have had no effect. Also attempted removing quotation marks from the URL as seen as an issue on Vercel, yet the problem remains unresolved with the server unable to resolve.</p>
<pre><code> server {
listen 80 default_server;
...
... (remaining content unchanged for brevity)
Any assistance would be greatly appreciated!