add login
Signed-off-by: garionion <github@entr0py.de>
This commit is contained in:
parent
e7cd3a4e6b
commit
788b45a9a7
3 changed files with 104 additions and 13 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue