Skip to content

Instantly share code, notes, and snippets.

@duwaljyoti
Last active January 27, 2018 03:33
Show Gist options
  • Select an option

  • Save duwaljyoti/53d64885b7fe0f229c6f49b78cdbfc11 to your computer and use it in GitHub Desktop.

Select an option

Save duwaljyoti/53d64885b7fe0f229c6f49b78cdbfc11 to your computer and use it in GitHub Desktop.
user/routes.js
import Vue from 'vue';
import Vuex from "vuex";
import VueRouter from 'vue-router';
import routes from './routes';
import store from './store';
Vue.use(VueRouter);
Vue.use(Vuex);
const router = new VueRouter({
routes,
});
// this works pretty fine..
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
console.log(window.loggedUser);
if(window.loggedUser) {
next();
} else {
window.location.href = window.location.origin + '/login';
}
}
next()
});
const userApp = new Vue({
router,
store,
});
userApp.$mount('#app');
================End of FIle====
authentcation.js
import VueRouter from 'vue-router';
import routes from './user/routes'
const router = new VueRouter({
routes,
});
// i can reach up to here..
but cant get inside the router for each...
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
console.log(window.loggedUser);
if(window.loggedUser) {
next();
} else {
window.location.href = window.location.origin + '/login';
}
}
next()
});
reason i am doing this is ..
i want authorization.js to handle the authorize part..
and just call it where necessary..
instead of writing the authorizin part everywhere.
any other work around?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment