fix: 企业登录拒绝 SUPER_ADMIN + authMiddleware 校验 orgId 非空,修复 500 错误
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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() },
|
||||
|
||||
Reference in New Issue
Block a user