fix(xo-server/updateUser): can remove password

This commit is contained in:
Julien Fontanet
2023-07-31 11:51:45 +02:00
committed by Florent BEAUCHAMP
parent aca19d9a81
commit 221cd40199

View File

@@ -150,8 +150,8 @@ export default class {
if (permission) {
user.permission = permission
}
if (password) {
user.pw_hash = await hash(password)
if (password !== undefined) {
user.pw_hash = password === null ? undefined : await hash(password)
}
const newPreferences = { ...user.preferences }
@@ -179,6 +179,10 @@ export default class {
user.authProviders = isEmpty(newAuthProviders) ? undefined : newAuthProviders
}
if (user.pw_hash === undefined && isEmpty(user.authProviders) && id === this.apiContext?.user.id) {
throw new Error('current user cannot be without password and auth providers')
}
// TODO: remove
user.email = user.name
delete user.name