Add route requiresAuth + redirect

This commit is contained in:
2020-04-13 00:19:52 +02:00
parent 7e846daa8d
commit 6487f932a8
2 changed files with 23 additions and 3 deletions
+16 -1
View File
@@ -8,6 +8,8 @@ import NoteCreation from '../views/NoteCreation.vue'
Vue.use(VueRouter)
import store from '../store';
const routes = [
{
path: '/',
@@ -27,7 +29,10 @@ const routes = [
{
path: '/note/new',
name: 'NoteCreation',
component: NoteCreation
component: NoteCreation,
meta: {
requiresAuth: true,
}
}
]
@@ -37,4 +42,14 @@ const router = new VueRouter({
routes
})
router.beforeEach((to, from, next) => {
// If user is not signed in -> redirect to /signin
if (to.matched.some(record => record.meta.requiresAuth) && !store.getters.isLoggedIn) {
next({
path: '/signin',
params: {nextUrl: to.fullPath}
})
} else
next()
})
export default router