X-Git-Url: https://git.auder.net/pieces/cn.svg?a=blobdiff_plain;f=client%2Fsrc%2Frouter.js;h=89bdf738a952337809fd8e66765677163294825f;hb=a7f9f050e44080e8caf888e3b230660abffa2400;hp=82f01009542d42f4d69a8844d5835473a96ad3a4;hpb=cf2343cee5729c011770ace6d5b4f79d1ac3a2b6;p=vchess.git diff --git a/client/src/router.js b/client/src/router.js index 82f01009..89bdf738 100644 --- a/client/src/router.js +++ b/client/src/router.js @@ -8,6 +8,9 @@ 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: [ { @@ -25,6 +28,46 @@ export default new Router({ 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",