From dbcb3dc7771db1e31a41d6279c3aecee6de7e0c7 Mon Sep 17 00:00:00 2001 From: tycrek Date: Mon, 26 Dec 2022 12:38:15 -0700 Subject: [PATCH] fix: CLI key not generating on first-time install --- src/auth.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/auth.ts b/src/auth.ts index a9f3c35..6c314d8 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -135,6 +135,12 @@ export const createNewUser = (username: string, password: string, admin: boolean if (!authData.meta) authData.meta = {}; + // Check if the CLI key is set + if (!authData.cliKey || authData.cliKey.length === 0) { + log.debug('CLI key is not set, generating new key'); + authData.cliKey = nanoid(32); + } + fs.writeJson(authPath, authData, { spaces: '\t' }) .then(() => log.info('Created new user', newUser.username, newUser.unid)) .then(() => resolve(newUser)) @@ -330,13 +336,6 @@ export const onStart = (authFile = 'auth.json') => new Promise((resolve, reject) return await createNewUser('ass', nanoid(), true); } - // Check if the CLI key is set - if (!json.cliKey || json.cliKey.length === 0) { - log.debug('CLI key is not set, generating new key'); - json.cliKey = nanoid(32); - fs.writeJsonSync(file, json, { spaces: '\t' }); - } - // Add users to the map return json.users.forEach((user) => users.push(user)); })