From acb666d0897250a0a5d39d43b661ad674b83a072 Mon Sep 17 00:00:00 2001 From: hex2077 Date: Thu, 25 Dec 2025 17:58:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20=E5=A4=84=E7=90=86=E7=A9=BA?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E6=96=87=E4=BB=B6=E6=97=B6=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当密码文件存在但内容为空时,现在会正确使用默认密码。同时优化了错误日志信息,使其更清晰。 --- src/ui-manager.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ui-manager.js b/src/ui-manager.js index 8e2901a..05a716a 100644 --- a/src/ui-manager.js +++ b/src/ui-manager.js @@ -209,17 +209,23 @@ const DEFAULT_PASSWORD = 'admin123'; * 读取密码文件内容 */ async function readPasswordFile() { + const pwdFilePath = path.join(process.cwd(), 'configs', 'pwd'); try { - const pwdFilePath = path.join(process.cwd(), 'configs', 'pwd'); if (!existsSync(pwdFilePath)) { console.log('[Auth] 密码文件不存在,使用默认密码'); return DEFAULT_PASSWORD; } const password = await fs.readFile(pwdFilePath, 'utf8'); - return password.trim(); + const trimmedPassword = password.trim(); + // 如果密码文件为空,使用默认密码 + if (!trimmedPassword) { + console.log('[Auth] 密码文件为空,使用默认密码'); + return DEFAULT_PASSWORD; + } + return trimmedPassword; } catch (error) { - console.error('读取密码文件失败:', error); - console.log('[Auth] 读取密码文件失败,使用默认密码'); + console.error('[Auth] 读取密码文件失败:', error.message); + console.log('[Auth] 使用默认密码'); return DEFAULT_PASSWORD; } }