Files
console-dev/app/utils/access.js
T

35 lines
1.1 KiB
JavaScript

/** 前端公开路由清单,供路由守卫和跨标签退出共用;后端接口仍须独立鉴权。 */
const authPages = new Set([
"/login",
"/register",
"/signup",
"/forgot-password",
"/forgot_password",
"/oauth/bind",
"/oauth/callback",
"/official-site",
]);
const shopPages = new Set([
"/products",
"/products/cloud-server",
"/products/cvm",
"/products/dedicated-server",
"/products/dedicated-server/customize",
]);
// 商品可匿名浏览,但 edit_position 表示编辑用户购物车,不能按公开商品页放行。
export function isPublicShop(route) {
if (Object.hasOwn(route.query || {}, "edit_position")) return false;
const path = route.path.replace(/\/+$/, "") || "/";
return shopPages.has(path) || /^\/products\/[1-9]\d*$/.test(path);
}
export function isAuthPage(path) {
return authPages.has(path.replace(/\/+$/, "") || "/");
}
// /home.htm 是待核验的过渡入口,公开仅表示能打开核验页,不表示已获登录权限。
export function isPublicRoute(route) {
return (
route.path === "/home.htm" || isAuthPage(route.path) || isPublicShop(route)
);
}