fix(release): close fixed-code mobile auth gaps

This commit is contained in:
key
2026-07-29 11:59:30 +08:00
parent 3c92edd23d
commit 70e5516ff3
21 changed files with 546 additions and 65 deletions
+12 -6
View File
@@ -2,7 +2,6 @@ import type { MobileIdentity, RoleKey } from '@/types/api';
import { apiRequest, isAuthApiError } from './api';
import {
clearOrgPosition,
getSelectedPosition,
hasOrgPosition,
isSupervisorLearnerMode,
leaveSupervisorLearnerMode,
@@ -43,14 +42,17 @@ export const routeForMobileRole = (role: RoleKey, requested: string) => {
export const hydrateMobileRole = async (): Promise<RoleKey> => {
try {
const identity = await fetchMobileIdentity();
const role = identity.role === 'supervisor' ? 'supervisor' : 'user';
if (identity.role !== 'user' && identity.role !== 'supervisor') {
throw new Error('组织角色无效,请联系管理员');
}
const role = identity.role;
uni.setStorageSync(roleKey, role);
if (role !== 'supervisor') leaveSupervisorLearnerMode();
return role;
} catch {
// ponytail: role lookup failure fails closed; never reuse a stale supervisor cache.
} catch (error) {
uni.removeStorageSync(roleKey);
return 'user';
clearOrgPosition();
throw error instanceof Error ? error : new Error('组织角色加载失败,请重试');
}
};
@@ -89,7 +91,11 @@ export const hydratePositionFromOrg = async (): Promise<UserPosition | ''> => {
const result = await fetchOrgPositionResult();
if (result.status === 'matched') return result.position;
if (result.status === 'unmatched') return '';
return hasOrgPosition() ? getSelectedPosition() : '';
clearOrgPosition();
if (result.status === 'unauthorized') {
throw new Error('登录已失效,请重新登录');
}
throw new Error('组织岗位加载失败,请检查网络后重试');
};
export const nextUserRouteAfterLogin = async (redirect: string) => {