feat: refactor authentication handling and migrate config to database

This commit is contained in:
SaelixCode
2026-03-04 09:05:03 -05:00
parent 6196ee7ccf
commit b45553c927
6 changed files with 524 additions and 379 deletions
+25
View File
@@ -50,6 +50,7 @@ export class DatabaseService {
// Default journal mode is safer for arbitrary Docker volume mounts than WAL
this.initSchema();
this.migrateJsonConfig(dataDir);
}
public static getInstance(): DatabaseService {
@@ -106,6 +107,30 @@ export class DatabaseService {
stmt.run('docker_janitor_gb', '5');
}
private migrateJsonConfig(dataDir: string) {
const configPath = path.join(dataDir, 'sencho.json');
if (fs.existsSync(configPath)) {
try {
const data = fs.readFileSync(configPath, 'utf-8');
const config = JSON.parse(data);
if (config.username && config.passwordHash && config.jwtSecret) {
const stmt = this.db.prepare('INSERT OR IGNORE INTO global_settings (key, value) VALUES (?, ?)');
stmt.run('auth_username', config.username);
stmt.run('auth_password_hash', config.passwordHash);
stmt.run('auth_jwt_secret', config.jwtSecret);
console.log('Successfully migrated sencho.json credentials to SQLite global_settings.');
// Delete the file after migrating
fs.unlinkSync(configPath);
}
} catch (err) {
console.error('Failed to migrate sencho.json:', err);
}
}
}
// --- Agents ---
public getAgents(): Agent[] {