X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Frouter.js;h=2030397a8dc95c5a09fc0b3d8b24d7977267d6ed;hp=82f01009542d42f4d69a8844d5835473a96ad3a4;hb=1aeed627be63a298d3a093797c3728e3de30b464;hpb=f05815d7da84284bd9d7c1ce5b808acd675f2a3e diff --git a/client/src/router.js b/client/src/router.js index 82f01009..2030397a 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,39 @@ export default new Router({ name: "rules", component: loadView("Rules"), }, + { + path: "/authenticate/:token", + name: "authenticate", + beforeEnter: (to, from, next) => { + ajax( + "/authenticate", + "GET", + {token: to.params["token"]}, + (res) => { + store.state.user.id = res.id; + store.state.user.name = res.name; + } + ); + next(); + }, + redirect: "/", + }, + { + path: "/logout", + name: "logout", + beforeEnter: (to, from, next) => { + ajax( + "/logout", + "GET", + () => { + store.state.user.id = 0; + store.state.user.name = ""; //TODO: localStorage myId myname mysid ? + } + ); + next(); + }, + redirect: "/", + }, // { // path: "/about", // name: "about",