fix: tighten H5 portal guard and legacy home stats

This commit is contained in:
Codex
2026-07-02 03:12:30 +08:00
parent 25ccaea873
commit e6735b58da
5 changed files with 156 additions and 12 deletions

View File

@@ -50,8 +50,17 @@ function isPublicPath(path: string) {
return path === '/pages/bootstrap/index' || path === '/pages/student/login/index';
}
export function isPathAllowedForPortal(path: string) {
if (isPublicPath(path)) return true;
if (!path.startsWith('/pages/')) return true;
if (appEnv.portal === 'tenant-admin') return path.startsWith('/pages/tenant-admin/');
if (appEnv.portal === 'platform-admin') return path.startsWith('/pages/platform-admin/');
return path.startsWith('/pages/student/');
}
export function shouldGuardPath(path: string) {
if (isPublicPath(path)) return false;
if (!isPathAllowedForPortal(path)) return true;
if (appEnv.portal === 'tenant-admin') return path.startsWith('/pages/tenant-admin/');
if (appEnv.portal === 'platform-admin') return path.startsWith('/pages/platform-admin/');
return path.startsWith('/pages/student/') && path !== '/pages/student/region/index';
@@ -107,6 +116,10 @@ export async function guardCurrentRoute() {
await ensureRuntimeConfigLoaded();
const path = currentPagePath();
if (!path || !shouldGuardPath(path)) return true;
if (!isPathAllowedForPortal(path)) {
redirectToAuthUrl(`/pages/bootstrap/index?redirect=${encodeURIComponent(landingPath())}`);
return false;
}
if (pendingGuardPath === path) return false;
pendingGuardPath = path;
try {