Skip to content

Commit

Permalink
fix(router): add authentication check before route navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
supersonictw committed Nov 14, 2024
1 parent 2a8050c commit 10af5a2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {createRouter, createWebHashHistory} from "vue-router";
import {useProfile, redirectLogin} from "../plugins/profile.js";

const routes = [
{
Expand Down Expand Up @@ -37,4 +38,18 @@ const router = createRouter({
routes,
});

router.beforeEach((to, _, next) => {
if (to.path === "/") {
next();
}

const profile = useProfile();
if (!profile) {
redirectLogin(true);
return;
}

next();
});

export default router;

0 comments on commit 10af5a2

Please sign in to comment.