Fix encryption not loading
This commit is contained in:
@@ -19,9 +19,20 @@ import { systemLogger, versionLogger } from "./utils/logger.js";
|
||||
const envPath = path.join(dataDir, ".env");
|
||||
try {
|
||||
await fs.access(envPath);
|
||||
dotenv.config({ path: envPath });
|
||||
// Load the persistent .env file and override process.env
|
||||
const persistentConfig = dotenv.config({ path: envPath });
|
||||
if (persistentConfig.parsed) {
|
||||
// Override process.env with values from persistent config
|
||||
Object.assign(process.env, persistentConfig.parsed);
|
||||
}
|
||||
systemLogger.info(`Loaded persistent configuration from ${envPath}`, {
|
||||
operation: "config_load"
|
||||
operation: "config_load",
|
||||
hasDatabaseKey: !!persistentConfig.parsed?.DATABASE_KEY,
|
||||
databaseKeyLength: persistentConfig.parsed?.DATABASE_KEY?.length || 0,
|
||||
hasJwtSecret: !!persistentConfig.parsed?.JWT_SECRET,
|
||||
jwtSecretLength: persistentConfig.parsed?.JWT_SECRET?.length || 0,
|
||||
hasInternalAuthToken: !!persistentConfig.parsed?.INTERNAL_AUTH_TOKEN,
|
||||
internalAuthTokenLength: persistentConfig.parsed?.INTERNAL_AUTH_TOKEN?.length || 0
|
||||
});
|
||||
} catch {
|
||||
// Config file doesn't exist yet, will be created on first run
|
||||
|
||||
@@ -76,8 +76,19 @@ class SystemCrypto {
|
||||
|
||||
// Check environment variable
|
||||
const envKey = process.env.DATABASE_KEY;
|
||||
databaseLogger.info("Checking DATABASE_KEY from environment", {
|
||||
operation: "db_key_check",
|
||||
hasKey: !!envKey,
|
||||
keyLength: envKey?.length || 0,
|
||||
meetsLengthRequirement: envKey && envKey.length >= 64
|
||||
});
|
||||
|
||||
if (envKey && envKey.length >= 64) {
|
||||
this.databaseKey = Buffer.from(envKey, 'hex');
|
||||
databaseLogger.info("Using existing DATABASE_KEY from environment", {
|
||||
operation: "db_key_use_existing",
|
||||
keyLength: envKey.length
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user