fix: 企业登录拒绝 SUPER_ADMIN + authMiddleware 校验 orgId 非空,修复 500 错误

This commit is contained in:
selfrelease
2026-07-29 12:01:14 +08:00
parent b1d2d5715d
commit b7e617cd0d
2 changed files with 8 additions and 0 deletions
+4
View File
@@ -17,6 +17,10 @@ export function authMiddleware(req: AuthRequest, res: Response, next: NextFuncti
return res.status(401).json({ success: false, error: { code: 'TOKEN_INVALID', message: '令牌无效或已过期' } })
}
req.user = payload
// 非 SUPER_ADMIN 用户必须有 orgId,否则企业端 API 会因 orgId=null 报错
if (payload.role !== 'SUPER_ADMIN' && !payload.orgId) {
return res.status(403).json({ success: false, error: { code: 'NO_ORG', message: '该账号未绑定企业' } })
}
next()
}
+4
View File
@@ -94,6 +94,10 @@ export async function login(phone: string, password: string) {
throw { code: 'ACCOUNT_DISABLED', message: '该账号已被禁用,请联系管理员' }
}
if (user.role === 'SUPER_ADMIN') {
throw { code: 'FORBIDDEN', message: '平台管理员请使用平台管理入口登录' }
}
await prisma.user.update({
where: { id: user.id },
data: { lastLoginAt: new Date() },