fix: auth file written before bcrypt Promise resolved

pull/177/head
tycrek 2 years ago
parent 1887409eeb
commit 619a30d685
No known key found for this signature in database
GPG Key ID: FF8A54DCE404885A

@ -43,23 +43,24 @@ const migrate = (): Promise<Users> => new Promise(async (resolve, reject) => {
newUsers.migrated = true; newUsers.migrated = true;
// Loop through each user // Loop through each user
Object.entries(oldUsers).forEach(async ([token, { username }]) => { await Promise.all(Object.entries(oldUsers).map(async ([token, { username }]) => {
// Determine if this user is the admin // Determine if this user is the admin
const admin = Object.keys(oldUsers).indexOf(token) === 0; const admin = Object.keys(oldUsers).indexOf(token) === 0;
const passhash = admin ? await bcrypt.hash(nanoid(32), SALT_ROUNDS) : '';
// Create a new user object // Create a new user object
const newUser: User = { const newUser: User = {
unid: nanoid(), unid: nanoid(),
username: username, username,
passhash: admin ? await bcrypt.hash(nanoid(32), SALT_ROUNDS) : '', passhash,
token, token,
admin, admin,
meta: {} meta: {}
}; };
newUsers.users.push(newUser); newUsers.users.push(newUser);
}); }));
// Save the new users object to auth.json // Save the new users object to auth.json
fs.writeJson(authPath, newUsers, { spaces: '\t' }) fs.writeJson(authPath, newUsers, { spaces: '\t' })

Loading…
Cancel
Save