Some checks are pending
Security Checks / security (push) Waiting to run
统一 frontend、backend、test、test-log 和 out 目录,更新构建、部署及测试入口;纳入配置管理兼容与首次安全引导修复;排除本机配置、密钥和测试产物。
126 lines
3.8 KiB
JavaScript
126 lines
3.8 KiB
JavaScript
import { createRouter, createWebHashHistory } from "vue-router";
|
|
import {useGlobalStatusStore} from "@/stores/useGlobalStatusStore";
|
|
import {AUTH_STATUS} from "@/utils/auth.mjs";
|
|
import {createLoginLocation, createSetupLocation} from "@/utils/navigation.mjs";
|
|
|
|
const router = createRouter({
|
|
history: createWebHashHistory(),
|
|
routes: [
|
|
{
|
|
path: "/",
|
|
name: "home",
|
|
component: () => import("../views/List/List.vue"),
|
|
meta: {requiresAuth: true}
|
|
},
|
|
{
|
|
path: "/list",
|
|
name: "list",
|
|
component: () => import("../views/List/List.vue"),
|
|
meta: {requiresAuth: true}
|
|
},
|
|
{
|
|
path: "/editer",
|
|
name: "editer",
|
|
component: () => import("../views/Editer/Editer.vue"),
|
|
meta: {requiresAuth: true}
|
|
},
|
|
{
|
|
path: "/login",
|
|
name: "login",
|
|
component: () => import("../views/Login/Login.vue")
|
|
},
|
|
{
|
|
path: "/login-verification",
|
|
name: "login-verification",
|
|
component: () => import("../views/LoginVerification/LoginVerification.vue")
|
|
},
|
|
{
|
|
path: "/force-password-change",
|
|
name: "force-password-change",
|
|
component: () => import("../views/ForcePasswordChange/ForcePasswordChange.vue"),
|
|
meta: {requiresAuth: true}
|
|
},
|
|
{
|
|
path: "/setup",
|
|
name: "setup",
|
|
component: () => import("../views/Setup/Setup.vue")
|
|
},
|
|
{
|
|
path: "/forgot-password",
|
|
name: "forgot-password",
|
|
component: () => import("../views/PasswordRecovery/PasswordRecovery.vue")
|
|
},
|
|
{
|
|
path: "/reset-blocked",
|
|
name: "reset-blocked",
|
|
component: () => import("../views/ResetBlocked/ResetBlocked.vue")
|
|
},
|
|
{
|
|
path: "/detail/:id",
|
|
name: "detail",
|
|
component: () => import("../views/EmailDetail/EmailDetail.vue"),
|
|
meta: {requiresAuth: true}
|
|
}
|
|
]
|
|
});
|
|
|
|
router.beforeEach(async (to) => {
|
|
const globalStatus = useGlobalStatusStore();
|
|
const needsAuthentication = to.meta.requiresAuth || to.name === "force-password-change";
|
|
let authStatus = globalStatus.isLogin
|
|
? AUTH_STATUS.AUTHENTICATED
|
|
: globalStatus.authStatus;
|
|
|
|
if (needsAuthentication && authStatus !== AUTH_STATUS.AUTHENTICATED) {
|
|
authStatus = await globalStatus.refresh();
|
|
}
|
|
|
|
if (needsAuthentication && authStatus === AUTH_STATUS.UNAVAILABLE) {
|
|
globalStatus.setAuthRetryPath(to.fullPath);
|
|
return false;
|
|
}
|
|
|
|
if (needsAuthentication && authStatus === AUTH_STATUS.NEEDS_SETUP) {
|
|
globalStatus.setAuthRetryPath(to.fullPath);
|
|
return createSetupLocation(to.fullPath);
|
|
}
|
|
|
|
if (!needsAuthentication && authStatus === AUTH_STATUS.UNAVAILABLE) {
|
|
globalStatus.resetAuthAvailability();
|
|
authStatus = AUTH_STATUS.UNKNOWN;
|
|
}
|
|
|
|
const authenticated = authStatus === AUTH_STATUS.AUTHENTICATED;
|
|
|
|
if (!authenticated && needsAuthentication) {
|
|
return createLoginLocation(to.fullPath);
|
|
}
|
|
|
|
if (authenticated) {
|
|
globalStatus.clearAuthRetryPath();
|
|
}
|
|
|
|
if (to.name === "force-password-change") {
|
|
if (!globalStatus.userInfos.must_change_password) {
|
|
return {name: "list"};
|
|
}
|
|
return true;
|
|
}
|
|
|
|
if (authenticated && globalStatus.userInfos.must_change_password) {
|
|
return {name: "force-password-change"};
|
|
}
|
|
|
|
if (!to.meta.requiresAuth) {
|
|
return true;
|
|
}
|
|
|
|
if (to.meta.capability && !globalStatus.hasCapability(to.meta.capability)) {
|
|
return {name: "list"};
|
|
}
|
|
|
|
return true;
|
|
});
|
|
|
|
export {router};
|