Search code examples
node.jshttpaxiosxmlhttprequestnuxt.js

Axios is not sending cookies even with withCredentials:true


i have a problem with my node.js nuxtjs app. I am sending requests with axios to api and on login request i get cookie normally. Everything works with recieving cookie from server, but when i GET another page, cookie isnt sending with it. Here are my OPTIONS on nodejs:

let options = { credentials: true, origin: "http://localhost:3000" };

app.use(cors(options))

Here is axios request:

export default async function ({ store, redirect }) {
  try {
    const res = await axios.get('http://127.0.0.1:5000/test', {
      withCredentials: true,
      credentials: 'include',
      allowCredentials: true,
    })
    console.error(res)
    store.commit('setAccess', res.data.access)
  } catch {
    return redirect('/register')
  }
}

Any ideas? Thanks for your time.


Solution

  • To justify my mistake. I thought that nuxtjs middleware is running on client, which is not true. So cookie was not sent. I solved it by redirecting to auth page (which can be running some nice spinning wheel) and the submiting the refresh token to server and getting new one.

    Thanks for your time and ideas !