A
A
Alexander Pankov2022-02-01 12:18:06
JSON Web Token
Alexander Pankov, 2022-02-01 12:18:06

How to fix request error when using nuxt/auth?

Hello, there is an application on nuxt
(online store)

I made a shopping cart (vuex) there, it's time to fasten authorization and registration,
googled such a module https://auth.nuxtjs.org/
chose the refresh scheme and set up nuxt.config according to the documentation

before connecting this there was no error component
now I get an error on the request the
request is inside the action store, which is responsible for the shopping cart

async fetch({commit, getters}) {
    const res = await this.$axios.$get(
      '/rest/cart/get/',
      {
        progress: false,
        headers: {'cart-uuid': getters.getUuid}
      })
    commit('setCart', res);
  },

here the cart is loaded with goods and the
cart uuid

store is mutated in cookies, this store action is called inside the cart component (cart.vue) in
the fetch method, it is executed when the page is first visited, it is in the js server

that the error itself sounds like this
Error in fetch(): TypeError: Cannot read properties of undefined (reading 'Authorization')


I don’t understand where and why, and then everything starts to work as it should, only at the first request from the server such a problem, by typing removed the headers setting from the request above (of course, in response, the code is different from 200, because the basket was not found) but also errors ( which is higher) then no

Please tell me what I do not understand?
am I overriding something in the wrong place, and the nuxt / auth module looks for the Authorization header and throws an error?
why is he looking for him? where is it stated? why only when working from the server?

I do not consider the option to make the cart component cient-only

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question