Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Parse.Cloud.define("inviteUser", async request => {
if (!request.user)
throw 'Must be signed in to call this Cloud Function.';
const {email, siteName} = request.params;
if (!email || !siteName)
throw 'Email or siteName is empty!';
console.log(`Send invite to ${email} ${new Date()}`);
const {AppCache} = require('parse-server/lib/cache');
const emailAdapter = AppCache.get(config.appId)['userController']['adapter'];
const emailSelf = request.user.get('email');
const link = `${SITE}/sign?mode=register&email=${email}`;
try {
await emailAdapter.send({
templateName: 'inviteEmail',
recipient: email,
variables: {siteName, emailSelf, link}
});
console.log(`Invite sent to ${email} ${new Date()}`);
return "Invite email sent!";
} catch (error) {
console.log(`Got an error in inviteUser: ${error}`);
throw error;