X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Frouter.js;h=89bdf738a952337809fd8e66765677163294825f;hb=a7f9f050e44080e8caf888e3b230660abffa2400;hp=b373cdc2232a1be2aa9fbe55b70e3b6b33751ff7;hpb=5b020e732156ee77d3b15b127aef2df57c2562ad;p=vchess.git diff --git a/client/src/router.js b/client/src/router.js index b373cdc2..89bdf738 100644 --- a/client/src/router.js +++ b/client/src/router.js @@ -1,6 +1,6 @@ import Vue from "vue"; import Router from "vue-router"; -import Home from "./views/Home.vue"; +import Hall from "./views/Hall.vue"; Vue.use(Router); @@ -8,23 +8,66 @@ function loadView(view) { return () => import(/* webpackChunkName: "view-[request]" */ `@/views/${view}.vue`) } +import { ajax } from "@/utils/ajax"; +import { store } from "@/store"; + export default new Router({ routes: [ { path: "/", - name: "home", - component: Home, + name: "hall", + component: Hall, }, { path: "/variants", name: "variants", component: loadView("Variants"), }, -// { -// path: "/variants/:vname([a-zA-Z0-9]+)", -// name: "rules", -// component: Rules, -// }, + { + path: "/variants/:vname([a-zA-Z0-9]+)", + name: "rules", + component: loadView("Rules"), + }, + { + path: "/authenticate/:token", + name: "authenticate", + beforeEnter: (to, from, next) => { + console.log("ajax call authenticate"); + ajax( + "/authenticate", + "GET", + {token: to.params["token"]}, + (res) => { + console.log(res); + store.state.user.id = res.id; + store.state.user.name = res.name; + store.state.user.email = res.email; + store.state.user.notify = res.notify; + // NOTE: mysid isn't cleared (required for potential game continuation) + next(); + } + ); + }, + redirect: "/", + }, + { + path: "/logout", + name: "logout", + beforeEnter: (to, from, next) => { + ajax( + "/logout", + "GET", + () => { + store.state.user.id = 0; + store.state.user.name = ""; + store.state.user.email = ""; + store.state.user.notify = false; + next(); + } + ); + }, + redirect: "/", + }, // { // path: "/about", // name: "about",