2022-11-23 08:39:29 +00:00
|
|
|
import { useUserStore } from "@/stores/user";
|
2022-10-11 09:00:14 +00:00
|
|
|
import type { Router } from "vue-router";
|
|
|
|
|
2024-09-28 10:19:41 +00:00
|
|
|
const whiteList = ["Setup"];
|
2023-03-30 09:44:15 +00:00
|
|
|
|
2022-10-11 09:00:14 +00:00
|
|
|
export function setupAuthCheckGuard(router: Router) {
|
2024-09-28 10:19:41 +00:00
|
|
|
router.beforeEach((to, _, next) => {
|
2022-11-23 08:39:29 +00:00
|
|
|
const userStore = useUserStore();
|
|
|
|
|
2023-03-23 14:52:34 +00:00
|
|
|
if (userStore.isAnonymous) {
|
2023-05-31 06:55:01 +00:00
|
|
|
if (whiteList.includes(to.name as string)) {
|
|
|
|
next();
|
|
|
|
return;
|
|
|
|
}
|
2024-09-28 10:19:41 +00:00
|
|
|
window.location.href = `/login?redirect_uri=${encodeURIComponent(
|
|
|
|
window.location.href
|
|
|
|
)}`;
|
2023-12-01 02:38:09 +00:00
|
|
|
return;
|
2022-10-11 09:00:14 +00:00
|
|
|
}
|
2023-05-31 06:55:01 +00:00
|
|
|
|
2022-10-11 09:00:14 +00:00
|
|
|
next();
|
|
|
|
});
|
|
|
|
}
|