fix: auth file written before bcrypt Promise resolved

pull/177/head
tycrek 1 year 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;
// 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
const admin = Object.keys(oldUsers).indexOf(token) === 0;
const passhash = admin ? await bcrypt.hash(nanoid(32), SALT_ROUNDS) : '';
// Create a new user object
const newUser: User = {
unid: nanoid(),
username: username,
passhash: admin ? await bcrypt.hash(nanoid(32), SALT_ROUNDS) : '',
username,
passhash,
token,
admin,
meta: {}
};
newUsers.users.push(newUser);
});
}));
// Save the new users object to auth.json
fs.writeJson(authPath, newUsers, { spaces: '\t' })

Loading…
Cancel
Save