Nuxt 3 is out! Discover more about it on https://nuxt.com/v3

Named Middleware

Using named middleware to authenticate a user using the store and allow them to visit a page once authenticated


In this example:

pages/named-middleware.vue contains a middleware property with the value of auth which is called before a user enters the route.

middleware/auth.js checks to see if the user is authenticated and if they aren't it redirects them to the auth page.

pages/auth.vue uses the store to authenticate the user.

store/auth.js sets the user and password values and redirects the user.

Loading Sandbox...
Edit this page on GitHub Updated at Tue, Dec 6, 2022