user12410550
user12410550

Reputation:

Vue - Nuxt - How to call a middleware on a layout?

I've created a middleware for authentication on my nuxt application, and I want to call it inside a layout. Problem is, I'm calling it like this:

export default {
  
  middleware: 'auth',

and it is returning me the following warning:

callback-based asyncData, fetch or middleware calls are deprecated. Please switch to promises or async/await syntax

I'm new into the front-end world and I searched but couldn't find/understand how to implement this async/await syntax on my middleware call. Can you help me? Thanks in advance.

Upvotes: 4

Views: 2735

Answers (1)

Faced a similar problem. I also use middleware: ['lang'], I got such an error and for a long time could not understand why this happened, if I did not change anything in the code. It turned out that in lang.js I mistakenly receive the second argument req

export default async function ({ isHMR, app, store }, req) {
}

Only a function servermiddleware can take multiple arguments

module.exports = function (req, res, next) {

Upvotes: 2

Related Questions