fix: resolve password migration crash and schema constraints
- Login bcrypt migration: write password_salt = '' instead of NULL, which violated the NOT NULL constraint and caused 500 errors - Schema: widen password_hash from CHAR(64) to VARCHAR(100) for bcrypt compatibility, add DEFAULT '' to password_salt - init-db: add ALTER TABLE migrations for existing databases - app.js: enrich error logging with method, path, SQL error details
这个提交包含在:
+1
-1
@@ -26,7 +26,7 @@ async function handle(event) {
|
||||
const body = await match.handler(ctx)
|
||||
return http(200, body)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
console.error('[ERROR]', ctx.method, ctx.path, err.code || '', err.sqlMessage || err.message, err.stack)
|
||||
return http(500, fail(3001, 'server_error'))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ function register(router) {
|
||||
// Try legacy SHA-256 verification for migration
|
||||
if (admin.password_salt && hashPasswordLegacy(password, admin.password_salt) === admin.password_hash) {
|
||||
// Auto-migrate to bcrypt
|
||||
const newHash = await hashPassword(password)
|
||||
await query('UPDATE admin_accounts SET password_hash = :password_hash, password_salt = NULL WHERE admin_id = :admin_id', { password_hash: newHash, admin_id: admin.admin_id })
|
||||
const newHash = hashPassword(password)
|
||||
await query('UPDATE admin_accounts SET password_hash = :password_hash, password_salt = :password_salt WHERE admin_id = :admin_id', { password_hash: newHash, password_salt: '', admin_id: admin.admin_id })
|
||||
matched = true
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户