Issues with Nuxt Authentication when deployed live

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!

Answer №1

It's recommended to configure the authentication origin with your genuine domain like https://your-domain instead of using https://localhost

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Scrolling the Ionic framework to a position below zero

My ion scroll is synchronized with another component for scrolling. I achieve this by using the function scroll1.scrollTo(left, top, false); Unfortunately, this function does not allow scrolling to a negative position, such as scroll1.scrollTo(left, -50, ...

Using Vue.js for handling events with the passing method

As a newcomer to Vue.js, I am currently trying to understand method event handling. My goal is to read a barcode using input from a web camera and display its raw content. The function works perfectly if I just render the raw content. However, when I att ...

The styling of HTML elements is ineffective when using scoped styles

I'm facing an issue where my element styling doesn't seem to work when using the scoped attribute. Upon inspecting the element, it appears that the styling is not being applied when using scoped. The reason I need to use scoped is because I want ...

employing the d3.queue method to defer execution until receiving the AJAX response

Seeking examples of integrating AJAX, d3, and PHP to extract data from a database and create graphs. Any guidance would be appreciated. I am currently using d3 to generate a force chart based on database information retrieved through AJAX and PHP. I have ...

Loading complex models with Three.js

Whenever I attempt to load a significantly large file utilizing the appropriate loaders provided by the library, the tab in which my website is running crashes. Despite trying to implement the Worker class, it doesn't seem to resolve the issue. Here i ...

Utilize Angular.js to effortlessly convert a string containing special characters and numbers into an array, and seamlessly display it using ng

I am a beginner in angular.js and I'm facing an issue with converting a string into an array and displaying it using ng-repeat. I found a custom filter from a stackoverflow question and here are the codes: JS: var app = angular.module('globalMo ...

Error: Improper hook call detected with no hooks being used (material-ui v5)

I've created the following basic application: import Grid from '@material-ui/core/Grid'; function App() { return ( <div className="App"> <Grid container spacing={2}> <Grid item xs={8}> ...

Update the href attribute when a button is clicked

Note: The buttons in the corner will not be submitting the search. The go button would still need to be clicked to submit it. Currently, I am working on a fun project during my free time at work. This project is not meant to be anything serious, but rathe ...

Troubleshooting Vue 3 component rendering issues in Laravel 8

My setup includes a basic blade file with a component embedded within: <section> <h1>Carousel</h1> <carousel :slides="@json($data->slides)"> </carousel> This is how the component is structured: <templa ...

Obtain JSON data instead of XML data from a web service through Ajax with the option 'contentType' set to 'false'

Upon making an AJAX call to send an image file to one of my web service (.asmx) methods, I encountered a problem where the web service returns XML instead of JSON. This issue arose because I needed to set the contentType to false, in order to successfully ...

Customized slider in jQuery UI allowing users to select height using a scaled ruler

Currently, I am tackling a challenging math problem related to adjusting the height selector input. Essentially, I have implemented a jQuery UI slider for choosing a height. It operates in inches and ranges from 0 to 120 (equivalent to 10 feet in height). ...

Using jQuery to dynamically load content from a link using Ajax

How can I modify a link element with an href link to a page to use Ajax to load that content from the href URL without redirecting the user to that page? I want to inject the content into the current page. <a class="bind-jquery-event-here-class" href=" ...

In Vue.js, the minus button will automatically disappear once the value reaches 0, and the plus button will reappear

I am trying to implement a functionality where, when the minus button is clicked and the value reaches 0, the minus button gets hidden and the plus button becomes visible again to add values. I have managed to make the minus and plus buttons work but nee ...

Tips for using res.json as a callback function

When using a function with a callback parameter, I found that this method works perfectly fine: DB.last(user,(data) => res.json(data)); However, when attempting to refactor it for better readability as shown below: DB.last(user,res.json); The structu ...

Having difficulty transferring navigation props between screens using react-navigation

Within my ContactList component, I have utilized a map to render various items. Each item includes a thumbnail and the desired functionality is that upon clicking on the thumbnail, the user should be directed to a new screen referred to as UserDetailsScree ...

setting a deadline for rendezvous with quasar version 1

Utilizing the quasar date component with restricted dates poses a challenge. In order to accomplish this, the documentation suggests utilizing the options prop which should be provided with an array or function. <template> <div class="q-pa- ...

The error message "Unable to execute stripe.customers.createBalanceTransaction function" is displayed on

Having trouble with a Type Error while attempting to use stripe's createBalanceTransaction function. You can find the API reference for the function here: https://stripe.com/docs/api/customer_balance_transactions/create The error message being receiv ...

The concept of setting a value is not defined in JavaScript when compared to

Within my primary python script, the following code snippet is present. @app.route('/accounts/test/learn/medium') def medium(): word = random.choice(os.listdir("characters/")) return render_template('accounts/test/medium.html', word=w ...

What is the significance of the message "Legacy octal literals are prohibited in strict mode" in the context of ReactJS?

I am encountering an issue while attempting to iterate through these arrays where I keep receiving the error message "Legacy octal literals are not allowed in strict mode." const myList =[ { id: 01, title: 'FrontEnd Engineer&apo ...

What is the method for invoking a function with a chosen date in the @syncfusion schedule with Angular 9?

capture of calendar display I am looking for a way to trigger a function with the selected date as a parameter. However, I am unable to locate the appropriate event to use within this module. Can someone provide assistance with this issue? Thanks! ...