{"size": 1167, "ext": "js", "max_stars_repo_path": "resources/js/routes/index.js", "max_stars_repo_name": "gogilo2003/bs", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "resources/js/routes/index.js", "max_issues_repo_name": "gogilo2003/bs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "resources/js/routes/index.js", "max_forks_repo_name": "gogilo2003/bs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.4736842105, "max_line_length": 48, "alphanum_fraction": 0.441302485}
import Vue from "vue";
import VueRouter from "vue-router";
import LoginVue from "../pages/Login.vue";
import ReadingsVue from "../pages/Readings.vue";
import Reading from "../pages/Reading.vue";
import Report from "../pages/Report.vue";

Vue.use(VueRouter)

const router = new VueRouter({
    mode: "history",
    routes: [
        {
            path: "/",
            component: ReadingsVue,
            meta: {
                auth: true
            }
        },
        {
            path: "/reading",
            component: Reading,
            meta: {
                auth: true
            }
        },
        {
            path: "/report",
            component: Report,
            meta: {
                auth: true
            }
        },
        {
            path: "/login",
            component: LoginVue,
            meta: {
                guest: true
            }
        }
    ]
})

let token = localStorage.getItem('token')
router.beforeEach((to, from, next) => {
    if (to.meta.auth) {
        if (token) {
            return next()
        } else {
            return next('login')
        }
    }
    return next()
})

export default router
