How can i have access vuex store in a nuxt 3 server middleware?

232 Views Asked by At

im currently working on integration a nuxt2 project into nuxt3 and in the nuxt2 project i had a middleware/single-use-token.ts file which contains something like this

export default function (context: any): void {

  const { stuffFromServer1, stuffFromServer2 } = (context.req && context.req.body) || {};

  if (stuffFromServer1 && stuffFromServer2) {
    // commit to store here
  }
}

i checked the migration guide here https://nuxt.com/docs/migration/plugins-and-middleware#route-middleware and im confused because this documentation looks different than the nuxt2 middleware documentation https://v2.nuxt.com/docs/directory-structure/middleware/.

Anyway, i think i need the nuxt3 server middleware approach to get the context.req. This is my code in server/middleware/single-use-token.ts yet:


export default defineEventHandler((event) => {
  const contextBody = event.node.req as any;
  const { stuffFromNode1, stuffFromNode2 } = contextBody.body;
  
  if (stuffFromNode1 && stuffFromNode2) {
    // commit to store
  }
});

Is it even possible to commit to the store on the nitro part of the app?

Cheers

i wrote down my research of the problem i found out on my own and asked the community to check it and asked explicit questions

0

There are 0 best solutions below