add login

Signed-off-by: garionion <github@entr0py.de>
This commit is contained in:
garionion 2021-04-03 17:41:47 +02:00
parent e7cd3a4e6b
commit 788b45a9a7
Signed by: garionion
GPG key ID: 53352FA607FA681A
3 changed files with 104 additions and 13 deletions

View file

@ -1,6 +1,8 @@
import { createWebHistory, createRouter } from "vue-router";
import Home from "../views/Home.vue";
import About from "../views/Settings.vue";
const Settings = () => import("../views/Settings.vue");
const Login = () => import("../views/Login.vue");
import { isLoggedIn } from "../api";
const routes = [
{
@ -11,7 +13,12 @@ const routes = [
{
path: "/settings",
name: "Settings",
component: About,
component: Settings,
},
{
path: "/login",
name: "Login",
component: Login,
},
];
@ -20,4 +27,12 @@ const router = createRouter({
routes,
});
router.beforeEach(async (to) => {
if (to.name !== "Login") {
const canAccess = await isLoggedIn();
if (!canAccess) return "/login";
}
return true;
});
export default router;