Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Vue from 'vue'
- import Router from 'vue-router'
- import firebase from 'firebase'
- const routerOptions = [
- { path: '/', component: 'Landing' },
- { path: '/signin', component: 'Signin' },
- { path: '/signup', component: 'Signup' },
- { path: '/home', component: 'Home', meta: { requiresAuth: true } },
- { path: '*', component: 'NotFound' }
- ]
- const routes = routerOptions.map(route => {
- return {
- ...route,
- component: () => import(`@/components/${route.component}.vue`)
- }
- })
- Vue.use(Router)
- const router = new Router({
- mode: 'history',
- routes
- })
- router.beforeEach((to, from, next) => {
- const requiresAuth = to.matched.some(record => record.meta.requiresAuth)
- const isAuthenticated = firebase.auth().currentUser
- if (requiresAuth && !isAuthenticated) {
- next('/signin')
- } else {
- next()
- }
- })
- export default router
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement