2023-11-16 07:51:19 +00:00
|
|
|
import { useUserStore } from "@/stores/user";
|
|
|
|
import type { Router } from "vue-router";
|
|
|
|
|
2023-12-01 03:06:09 +00:00
|
|
|
const whiteList = ["ResetPassword"];
|
|
|
|
|
2023-11-16 07:51:19 +00:00
|
|
|
export function setupAuthCheckGuard(router: Router) {
|
|
|
|
router.beforeEach((to, from, next) => {
|
2023-12-01 03:06:09 +00:00
|
|
|
if (whiteList.includes(to.name as string)) {
|
|
|
|
next();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-16 07:51:19 +00:00
|
|
|
const userStore = useUserStore();
|
|
|
|
|
|
|
|
if (userStore.isAnonymous) {
|
2024-09-28 09:38:32 +00:00
|
|
|
window.location.href = `/login?redirect_uri=${encodeURIComponent(
|
2023-11-16 07:51:19 +00:00
|
|
|
window.location.href
|
|
|
|
)}`;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
}
|