Problem with Nuxt Authentication in Production

I am trying to deploy a nuxt application in a server. The server uses nginx and acts as proxy to localhost. Everything seems fine, I can already access the appliaction with the domain of the server and I can make api calls to the server. However, the authentication does not work. I am using sidebase nuxt auth and when I am trying to login an user I get the error shown in the image.

Error in the browser’s console after an user tries to authenticate

To run the server I use pm2 and this is the ecosystem.config.cjs file:

module.exports = {
    apps: [
    {
    name: 'eurocore-coopetition',
    port: '3000',
    exec_mode: 'cluster',
    instances: '1',
        script: './.output/server/index.mjs'
    }
    ]
}
  

And this is my nuxt.config.ts file:

// 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/ .

And this is my […].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
  }
}

export default NuxtAuthHandler({
  pages: {
    signIn: "/login",
  },
  session: {
    strategy: "jwt"
  },
  callbacks: {
    jwt: async ({token, user}) => {
      const isSignIn = user ? true : false;
      if (isSignIn){
        token.id = user.id;
        token.name = user.name;
        token.email = user.email;
        token.role = user.role;
        //token.jwt = user ? (user as any).acess_token || '' : '';
        //token.id = user ? user.id || '' : '';
        //token.role = user ? (user as any).role || '' : '';

      }
      return token;
    },

    session: async ({session, token}) => {
      (session as any).uid = token.id;
      (session as any).role = token.role;
      return session;
    }
  },
  secret: config.authSecret,
  adapter: PrismaAdapter(prisma),
  providers: [
    // @ts-expect-error
    CredentialsProvider.default({
      name: "Credentials",
      async authorize(credentials: {email: string, password: string}) {
        const user = await prisma.users.findUnique({where: { email: credentials.email }})
        let valid;
        if (user) {
          valid = await bcrypt.compare(credentials.password, user.password);
        }
        
        if(!user || !valid){
          throw createError({
            statusCode: 403,
            statusMessage: "Credentials not working",
          })
        }
        return user
      },
    }),
  ],
})

I have tried to change the baseURL to the domain of the server but that did not work and it did not load any page. In development mode everything works if I test the deployment in my computer using pm2 it also works. So I don’t know what it’s the problem.

Any help is appreciated!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật