From 872bc9df75427ffe742cfc169729dfc99210e195 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Tue, 30 Jun 2020 20:08:52 +0200 Subject: [PATCH] :bug: Write env encryption key to config if file does not exist #713 --- packages/core/src/UserSettings.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core/src/UserSettings.ts b/packages/core/src/UserSettings.ts index 211341ed25..fb38fc779c 100644 --- a/packages/core/src/UserSettings.ts +++ b/packages/core/src/UserSettings.ts @@ -41,8 +41,13 @@ export async function prepareUserSettings(): Promise { userSettings = {}; } - // Settings and/or key do not exist. So generate a new encryption key - userSettings.encryptionKey = randomBytes(24).toString('base64'); + if (process.env[ENCRYPTION_KEY_ENV_OVERWRITE] !== undefined) { + // Use the encryption key which got set via environment + userSettings.encryptionKey = process.env[ENCRYPTION_KEY_ENV_OVERWRITE]; + } else { + // Generate a new encryption key + userSettings.encryptionKey = randomBytes(24).toString('base64'); + } console.log(`UserSettings got generated and saved to: ${settingsPath}`);