WPX 桌面端 v0.1.18,修复了几个bug
Latest
Compare
Sorry, something went wrong.
No results found
fix(admin): 修复登录后跳到 /forbidden - admin SPA 角色识别 bug
问题:admin 用户用 test-prod@prowpx.com 登录成功(HTTP 200 + JWT),
但 admin SPA 的路由守卫判定无权限,强行跳转到 /forbidden。
根因 1:admin SPA 角色枚举 (admin/src/utils/roles.js) 只接受
super_admin / operation_admin / content_editor,不接受后端
users 表第一个用户 bootstrap 时被授予的 'admin' 角色。
根因 2:admin auth store (admin/src/stores/auth.js) 把 role getter 写成
const role = computed(() => user.value?.role || null)
但后端 /api/auth/login 响应里 user 只有顶层 roles 数组(来自
server/models/user.js toPublic),没有顶层 role 字段。
所以 auth.role 永远是 null → hasPermission(...) 检查失败 → /forbidden。
修复:
1. roles.js 新增 ROLES.ADMIN = 'admin' 别名(与 ROLES.SUPER_ADMIN 等价),
把 ADMIN 加入所有 MODULE_PERMISSIONS 的允许列表、ROLE_LABELS 中文名、
ROLE_LEVEL 同 100 等级、ROLE_HOME 跳 /dashboard。
2. auth.js role getter 改为按优先级读取:
user.role → user.roles[0] → decodeRoleFromJwt(token)
并新增 roles computed(数组,供多角色检查使用)。
3. 重新构建 admin SPA(vite build),新 hash:
- index-CmMB_IB8.js(之前 DChd-Now)
- AdminLayout-IF_yzszh.js(之前 x3MfSxJy)
- LoginView-CpkVZziL.js 等
附带:把上次遗漏的 public/api/proxy.js 修复(apex→www 同源 + parse-body
注入)一起提交。
验证步骤:部署后用 test-prod@prowpx.com 登录,预期直接跳到 /dashboard
而不是 /forbidden。