发布前校验是否实名认证

This commit is contained in:
yml
2026-05-23 00:01:03 +08:00
parent 94edda9710
commit efb3b94286
5 changed files with 62 additions and 5 deletions
+20 -2
View File
@@ -1,5 +1,6 @@
import { createRouter, createWebHistory } from "vue-router";
import { useSessionStore } from "@/stores/session";
import { isMobileHost, toMobilePath } from "./mobileHost";
const router = createRouter({
@@ -65,7 +66,7 @@ const router = createRouter({
name: "mobile-seller-listing-create",
component: () =>
import("@/views/mobile/MobileSellerListingCreateView.vue"),
meta: { layout: "blank", requiresAuth: true },
meta: { layout: "blank", requiresAuth: true, requiresRealname: true },
},
{
path: "/",
@@ -212,7 +213,7 @@ const router = createRouter({
],
});
router.beforeEach((to) => {
router.beforeEach(async (to) => {
if (isMobileHost() && to.path !== toMobilePath(to.path)) {
return { path: toMobilePath(to.path), query: to.query, hash: to.hash };
}
@@ -221,6 +222,23 @@ router.beforeEach((to) => {
return { path: "/m/login", query: { redirect: to.fullPath } };
}
if (to.meta.requiresRealname) {
const session = useSessionStore();
if (session.realnameStatus !== "verified") {
try {
await session.loadMe();
} catch {
if (!localStorage.getItem("access_token")) {
return { path: "/m/login", query: { redirect: to.fullPath } };
}
}
}
if (session.realnameStatus !== "verified") {
return { path: "/m/realname", query: { redirect: to.fullPath } };
}
}
if (
to.path === "/admin/login" &&
localStorage.getItem("admin_access_token")