Async Versions of Meteor 2.8 Accounts Functions?

I’m looking for the correct way to remove Promise.await from my usage of Accounts.onCreateUser and Accounts.emailTemplates.verifyEmail .

In Meteor 2.8, are there async versions of these functions? I don’t see references to calling them async yet in the 2.8 Meteor docs.

As an example of what I’m trying to do, I tried this:

Accounts.onCreateUser((options, user) => {
	async function manageAsynOperations(options, user) {
		let args = {};
		args.id = user._id;

		args.name_first = options.first_name;
		args.name_last = options.last_name;
		const newEPUser = await connectors.epUserData.create(args);

		if (args.name_first){
			let sql = `UPDATE "epUserDatum"
					   SET "epUserNumber" =  nextval('epUserNumber_seq')
					   WHERE "id" = '${args.id}';`
			console.log("checkpoint# 7");

			let results = await getQueryResults(sql);
		}
		console.log("checkpoint# 8");
		return new Promise((resolve, reject) => {
			console.log("checkpoint# 8b");
			resolve(user)
		})
	}
	console.log("checkpoint# 9");
	user = manageAsynOperations(options, user);
	console.log("checkpoint# 10");
	return user;
});

I need all the async calls to finish before the function exits. So of course, this did not work, as the function exits (“checkpoint# 10”) before the async calls have finished (“checkpoint# 8”).

Hello there! we have plans on having async methods for user accounts. They will be in 2.9.x Release 2.9 by denihs · Pull Request #12273 · meteor/meteor · GitHub

For now, you can keep using Promise.await but in 3.x they can be replaced by just an await keyword

3 Likes

Thanks very much for this info! That’s going to make this very easy.

3 Likes