Skip to content

Commit

Permalink
feat: new props allowed on user update and event emitted (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
rombat authored Jul 22, 2024
1 parent 4a23594 commit 3c5b059
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion services/auth/lib/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function updateMe(req, res) {
return helpers.unauthorized(res);
}

const allowedProps = ['displayName', 'data', 'identities', 'email'];
const allowedProps = ['displayName', 'data', 'identities', 'email', 'firstName', 'lastName'];
const update = { $set: {} };

allowedProps.forEach(prop => {
Expand All @@ -126,13 +126,20 @@ async function updateMe(req, res) {
}
});

if (!Object.keys(update.$set).length) {
return helpers.badRequest(res, new Error('No valid properties to update'));
}

try {
const usersCollection = await getUsersCollection(req.campsi, req.service.path);
const result = await usersCollection.findOneAndUpdate({ _id: req.user._id }, update, {
returnDocument: 'after',
projection: { 'identities.local.encryptedPassword': 0 }
});
res.json(result);

delete update.$set.identities?.local?.encryptedPassword;
req.service.emit('user/updated', { userId: req.user._id, update: update.$set });
} catch (e) {
helpers.error(res, e);
}
Expand Down

0 comments on commit 3c5b059

Please sign in to comment.