debug: 添加权限过滤日志定位问题
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
kkfluous
2026-04-02 16:48:29 +08:00
parent 4cd76b6a30
commit 143c1a57bb

View File

@@ -312,8 +312,15 @@ async function getVehicles(): Promise<Vehicle[]> {
async function getVehiclesForUser(c: Context): Promise<Vehicle[]> {
const all = await getVehicles();
const user = c.get('user') as AuthUser | undefined;
return user ? filterByPermission(all, user) : all;
// Hono 子路由 context 可能丢失变量,尝试多种方式获取
const user = ((c as any).get?.('user') || (c as any).var?.user) as AuthUser | undefined;
if (user) {
const filtered = filterByPermission(all, user);
console.log(`[vehicles] permission: ${user.permissionLevel}, user: ${user.userName}, before: ${all.length}, after: ${filtered.length}`);
return filtered;
}
console.log('[vehicles] WARNING: no user in context, returning all');
return all;
}
function getRegionCounts(vehicles: Vehicle[], regions: readonly string[]): Record<string, number> {