Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
Why Nuxt making multiple request for the "user" endpoint?

There is an Express server and a Nuxt client. Nuxt version is 2.15.7.

Entire auth configuration:

// nuxt.config.js
auth: {
  plugins: [
    {
      src: '~/plugins/axios',
      ssr: true
    },
    {
      src: '~/plugins/auth'
    }
  ],
  cookie: {
    prefix: 'auth.',
    options: {
      path: '/',
      secure: process.env.NODE_ENV === 'production' ? true : false
    }
  },
  localStorage: {
    prefix: 'auth.'
  },
  vuex: {
    namespace: 'auth'
  },
  strategies: {
    local: {
      scheme: 'refresh',
      token: {
        property: 'accessToken',
        maxAge: 900,
        global: true,
        name: 'Authorization',
        type: 'Bearer'
      },
      refreshToken: {
        property: 'refreshToken',
        data: 'refreshToken',
        maxAge: 5184000
      },
      user: {
        property: 'user',
        autoFetch: false
      },
      endpoints: {
        login: {
          url: '/user/sign_in',
          method: 'post'
        },
        logout: {
          url: '/user/sign_out',
          method: 'delete'
        },
        refresh: {
          url: '/user/refresh',
          method: 'get'
        },
        user: {
          url: '/user/profile',
          method: 'get'
        }
      }
    }
  },
  redirect: {
    login: '/auth/sign_in',
    logout: '/',
    callback: '/auth/sign_in',
    home: '/'
  }
}

When I refresh the page in the browser, I see this in the browser log:

enter image description here

This message comes from here:

// plugins/axios.ts
import { AxiosRequestConfig } from 'axios'

export default function ({ $axios, }: any) {
  $axios.onRequest((config: AxiosRequestConfig) => {
    console.log('Making request to ' + config.url)
  })
}

There are also two requests in the server logs. But in the first request I can get, for example, cookies, and in the second one comes this:

// console.log(req.cookies)

[Object: null prototype] {}

Can you please tell me why there are two requests?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The problem was caused by the back end returning this after sign in:

{
  "is": 1
}

And should return this:

{
  "user": {
    "is": 1
  }
}

😬

After I added the "user" object, nuxt auth accepted the information and started working correctly.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda