nuxt-community / axios-module

Secure and easy axios integration for Nuxt 2
https://axios.nuxtjs.org
MIT License
1.2k stars 245 forks source link

Authorization header is not being set with Auth Module cookie strategy #607

Open sadeghi-aa opened 11 months ago

sadeghi-aa commented 11 months ago

Hi. I have a NuxtJS project that is running on SSR mode and the auth module configuration is like this:

  auth: {
    redirect: {
      login: '/login,
      logout: '/',
      home: '/',
      callback: false,
    },
    rewriteRedirects: true,
    resetOnError: false,
    fullPathRedirect: true,
    strategies: {
      local: false,
      cookie: {
        token: {
          property: 'data.token',
          required: true,
        },
        options: {
          expires: 7,
          path: '*',
          httpOnly: true,
          secure: true,
        },
        endpoints: {
          login: { url: '/login/', method: 'post' },
          logout: { url: '/logout/', method: 'post' },
          user: false,
        },
        user: {
          property: false,
          autoFetch: true,
        },
      },
    },
    plugins: [
      '~/plugins/auth.js',
      '~/plugins/axios',
    ],
  },

The problem is that Axios doesn't set the Authorization header in the requests after login. I worked around this issue by using the setToken helper in the client side, but this doesn't help with the requests made on the server side. How can I solve this issue?

I didn't have this issue with local strategy. I also tried setting credentials: true in the axios configuration but it didn't help.