todos-contra-el-fuego-web/imports/api/Users/server/methods.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

56 lines
1.6 KiB
JavaScript

/* eslint-disable import/no-absolute-path */
import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import { Accounts } from 'meteor/accounts-base';
import urlEnc from '/imports/modules/url-encode';
import editProfile from './edit-profile';
import rateLimit from '../../../modules/rate-limit';
const validLangCode = Match.Where((lang) => {
check(lang, String);
const regexp = /^[a-z]{2,3}(?:-[A-Z]{2,3}(?:-[a-zA-Z]{4})?)?$/;
return regexp.test(lang);
});
Meteor.methods({
'users.sendVerificationEmail': function usersSendVerificationEmail() {
return Accounts.sendVerificationEmail(this.userId);
},
'users.editProfile': function usersEditProfile(profile) {
check(profile, {
emailAddress: String,
profile: {
name: {
first: String,
last: String
}
}
});
return editProfile({ userId: this.userId, profile })
.then(response => response)
.catch((exception) => {
throw new Meteor.Error('500', exception);
});
},
'users.setLang': async function userLang(lang) {
check(lang, validLangCode);
await Meteor.users.updateAsync({ _id: this.userId }, { $set: { lang } });
},
'auth.getHash': async function getHash() {
const token = Accounts._generateStampedLoginToken();
const obj = Accounts._hashStampedToken(token);
// console.log(obj);
const sealed = await urlEnc.encrypt(obj);
return sealed;
}
});
rateLimit({
methods: [
'users.sendVerificationEmail',
'users.editProfile'
],
limit: 5,
timeRange: 1000
});