mirror of
https://github.com/ZeroCatDev/ClassworksKV.git
synced 2026-02-03 23:23:10 +00:00
fix: standardize autoAuth field names to autoauth in apps and auto-auth routes
This commit is contained in:
parent
c063dcf5b6
commit
dc5de6e63a
@ -179,7 +179,7 @@ router.post(
|
||||
const device = await prisma.device.findUnique({
|
||||
where: {namespace},
|
||||
include: {
|
||||
autoAuths: true,
|
||||
autoauths: true,
|
||||
},
|
||||
});
|
||||
|
||||
@ -193,11 +193,11 @@ router.post(
|
||||
// 如果提供了密码,查找匹配密码的自动授权
|
||||
if (password) {
|
||||
// 首先尝试直接匹配明文密码
|
||||
matchedAutoAuth = device.autoAuths.find(auth => auth.password === password);
|
||||
matchedAutoAuth = device.autoauths.find(auth => auth.password === password);
|
||||
|
||||
// 如果没有匹配到,尝试验证哈希密码(向后兼容)
|
||||
if (!matchedAutoAuth) {
|
||||
for (const autoAuth of device.autoAuths) {
|
||||
for (const autoAuth of device.autoauths) {
|
||||
if (autoAuth.password && autoAuth.password.startsWith('$2')) { // bcrypt 哈希以 $2 开头
|
||||
try {
|
||||
if (await verifyDevicePassword(password, autoAuth.password)) {
|
||||
@ -225,7 +225,7 @@ router.post(
|
||||
}
|
||||
} else {
|
||||
// 如果没有提供密码,查找密码为空的自动授权
|
||||
matchedAutoAuth = device.autoAuths.find(auth => !auth.password);
|
||||
matchedAutoAuth = device.autoauths.find(auth => !auth.password);
|
||||
|
||||
if (!matchedAutoAuth) {
|
||||
return next(errors.createError(401, "需要提供密码"));
|
||||
|
||||
@ -30,13 +30,13 @@ router.get(
|
||||
return next(errors.createError(403, "该设备未绑定到您的账户"));
|
||||
}
|
||||
|
||||
const autoAuths = await prisma.autoAuth.findMany({
|
||||
const autoauths = await prisma.autoAuth.findMany({
|
||||
where: {deviceid: device.id},
|
||||
orderBy: {createdat: 'desc'},
|
||||
});
|
||||
|
||||
// 返回配置,智能处理密码显示
|
||||
const configs = autoAuths.map(auth => {
|
||||
const configs = autoauths.map(auth => {
|
||||
// 检查是否是 bcrypt 哈希密码
|
||||
const isHashedPassword = auth.password && auth.password.startsWith('$2');
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user