todos-contra-el-fuego-web/imports/api/Users/server/edit-profile.js
vjrj 775461f7b2
All checks were successful
build-image / build (push) Successful in 12m38s
fix(users): use updateAsync for Meteor 3 server-side user writes
Meteor.users.update() is sync-only and no longer exists server-side
under Meteor 3, so it threw on every call, surfacing as a generic
500 to the client. users.setLang runs on every page load for logged-in
users, which is what broke /zones; the same bug in edit-profile.js
was silently breaking /profile too.
2026-07-30 10:13:21 +02:00

32 lines
740 B
JavaScript

/* eslint-disable consistent-return */
import { Meteor } from 'meteor/meteor';
let action;
const updateUser = async (userId, { emailAddress, profile }) => {
try {
await Meteor.users.updateAsync(userId, {
$set: {
'emails.0.address': emailAddress,
profile,
},
});
} catch (exception) {
action.reject(`[editProfile.updateUser] ${exception}`);
}
};
const editProfile = async ({ userId, profile }, promise) => {
try {
action = promise;
await updateUser(userId, profile);
action.resolve();
} catch (exception) {
action.reject(`[editProfile.handler] ${exception}`);
}
};
export default options =>
new Promise((resolve, reject) =>
editProfile(options, { resolve, reject }));