Skip to content

Commit

Permalink
Fix jwt_private_key not added after migration
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoGheza committed Mar 21, 2022
1 parent f8b49ba commit 5370be8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/_helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Config } from "../_models/Config";
import { ConfigTSLClient } from "../_models/ConfigTSLClient";
import fs from "fs-extra";
import path from "path";
import { randomBytes } from "crypto";
import { clone } from "./clone";
import { uuidv4 } from "./uuid";
import { addUser } from "./auth";
Expand All @@ -20,7 +21,7 @@ const config_file = getConfigFilePath();

export const ConfigDefaults: Config = {
security: {
jwt_private_key: require('crypto').randomBytes(256).toString('base64'),
jwt_private_key: "",
},
users: [],
cloud_destinations: [],
Expand All @@ -39,7 +40,7 @@ export const ConfigDefaults: Config = {
],
externalAddress: "http://0.0.0.0:4455/#/tally",
remoteErrorReporting: false,
uuid: uuidv4()
uuid: ""
}

export let currentConfig: Config = clone(ConfigDefaults);
Expand Down Expand Up @@ -87,7 +88,7 @@ export function readConfig(): void {
...clone(ConfigDefaults),
...loadedConfig,
};
if(!loadedConfig.users || loadedConfig.users.length === 0) {
if(!loadedConfig.users || typeof loadedConfig.users !== "object" || loadedConfig.users.length === 0) {
logger('Migrating user configs to the new format.', 'info-quiet');
currentConfig.users = [];
addUser({
Expand All @@ -106,12 +107,14 @@ export function readConfig(): void {
delete currentConfig.security.password_settings;
SaveConfig();
}
if(!loadedConfig.uuid) {
if(!loadedConfig.uuid || typeof loadedConfig.uuid !== "string") {
logger('Adding an uuid identifier to this server for using MDNS.', 'info-quiet');
currentConfig.uuid = uuidv4();
SaveConfig(); //uuid added if missing on config save
}
if(!loadedConfig.security.jwt_private_key) {
if(!loadedConfig.security.jwt_private_key || typeof loadedConfig.security.jwt_private_key !== "string") {
logger('Adding a private key for JWT authentication.', 'info-quiet');
currentConfig.security.jwt_private_key = randomBytes(256).toString('base64');
SaveConfig(); //uuid added if missing on config save
}
}
Expand Down

0 comments on commit 5370be8

Please sign in to comment.