added login stuff
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-12-06 01:43:47 +01:00
parent 0a09a1b0b7
commit 633f2af5eb
11 changed files with 255 additions and 33 deletions

View File

@@ -3,18 +3,30 @@ import VueRouter from 'vue-router'
import Dashboard from '@/views/Dashboard'
import Welcome from "@/views/Welcome";
Vue.use(VueRouter)
import store from '@/store'
Vue.use(VueRouter);
const routes = [
{
path: '/',
path: '/welcome',
name: 'Welcome',
component: Welcome
component: Welcome,
meta: {
allowVisit(loggedin) {
return !loggedin;
}
}
},
{
path: '/dashboard',
path: '/',
name: 'Dashboard',
component: Dashboard
component: Dashboard,
meta: {
allowVisit(loggedin) {
return loggedin;
}
}
},
{
path: '/about',
@@ -22,7 +34,12 @@ const routes = [
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '@/views/About.vue')
component: () => import(/* webpackChunkName: "about" */ '@/views/About.vue'),
meta: {
allowVisit() {
return true;
}
}
}
]
@@ -32,4 +49,25 @@ const router = new VueRouter({
routes
})
router.beforeEach((to, from, next) => {
const loggedin = store.getters.isLoggedIn;
const visitAllowed = to.matched.some(record => record.meta.allowVisit(loggedin))
if (visitAllowed) {
next();
return;
}
if (loggedin) {
next({name: 'Dashboard'})
} else {
next({name: 'Welcome'})
}
})
export default router