Search code examples
nuxt.jsmiddleware

Nuxt Middleware not executed


In my Nuxt Project I have a folder "middleware" with a file "addresses.js" When I try to use it with my page:

export default {
  middleware: "addresses",
}

it does not get executed.

addresses.json:

export default async ({ $axios, store }) => {

    console.log("test")
  var data = JSON.stringify({
    identifier: "tobias@mreich.de",
    password: "123456",
  });

  var config = {
    method: "get",
    url: "http://192.168.190.112:1337/api/users/me?populate=addresses",
    headers: {
      "Content-Type": "application/json",
    },
    data: data,
  };

  let request1 = await $axios(config)
    .then(function (response) {
      console.log(JSON.stringify(response.data));
    })
    .catch(function (error) {
      console.log(error);
    });
    console.log(request1.data)
    return store.commit("setAddresses", [request1.data])
};


Solution

  • Actually found it myself. I was using middleware: addresses in a component. I moved it to the actual page. Works fine now.