Wednesday, March 15, 2017

outer.beforeEach in laravel 5.4

I have problem in my app, I use laravel 5.4 and vue.js 2x

I use outer.beforeEach() to handle authorization in my app. but I have problem , my function outer.beforeEach() just load in one moment after login. if I refresh page outer.beforeEach() not call again.

this may code :

import router from './routes.js';
require('./bootstrap');

const app = new Vue({
    el: '#app',
    router,
});


router.beforeEach((to,from,next) => {
    if(to.meta.requiresAuth){
        authUser = '';
        const authUser = JSON.parse(window.localStorage.getItem('authUser'))
        if(authUser && authUser.access_token){
            next()
        }else{
            next({
                path: '/login',
                query: { redirect: to.fullPath }
            })
        }
    }
    next()
})

and full project : https://github.com/jrpikong/wingding



via user3230375

Advertisement