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.
Learn more in the Directory Structure book in the middleware  chapter.
 Loading Sandbox...
 
        Edit this page on GitHub
        
      Updated at Fri, Jan 20, 2023
    
 
 
        Rishi Raj Jain
       
 
        Clément Ollivier
       
 
        Savas Vedova
       
 
        Steven Soekha
       
 
        Vinícius Alves
       
 
        Kareem Dabbeet
       
 
        Valentín Costa
       
 
        Ryan Skinner
       
 
        Daniel Roe
       
 
        Alex Hirzel
       
 
        Ajeet Chaulagain
       
 
        René Eschke
       
 
        Sébastien Chopin
       
 
        Nico Devs
       
 
        Muhammad
       
 
        Nazaré da Piedade
       
 
        Naoki Hamada
       
 
        Tom
       
 
        Yann Aufray
       
 
        Anthony Chu
       
 
        Nuzhat Minhaz
       
 
        Lucas Portet
       
 
        Richard Schloss
       
 
        Bobby Jenkins
       
 
        bpy
       
 
        Antony Konstantinidis
       
 
        Hibariya
       
 
        Jose Seabra
       
 
        Eze
       
 
        Florian LEFEBVRE
       
 
        Lucas Recoaro
       
 
        Julien SEIXAS
       
 
        Hugo
       
 
        Sylvain Marroufin
       
 
        Spencer Cooley
       
 
        Piotr Zatorski
       
 
        Vladimir Semenov
       
 
        Harry Allen
       
 
        kazuya kawaguchi
       
 
        Unai Mengual
       
 
        Hyunseung Lee
       
 
        Alexandre Chopin
       
 
        pooya parsa
       
 
        Nick Medrano
       
 
        Mosaab Emam
       
 
        Iljs Путлер Капут
       
 
        Heitor Ramon Ribeiro
       
 
        Nero
       
 
        Yoon Han
       
 
        Ikko Eltociear Ashimine
       
 
        FamCodings
       
 
        Ayouli
       
 
        F. Hinkelmann
       
 
        felipesuri
       
 
        Christophe Carvalho Vilas-Boas
       
 
        Leoš Literák
       
 
        Trizotti
       
 
        Marcello Bachechi
       
 
        Rodolphe
       
 
        Thomas Underwood