emailjs-com/emailjs-sdk

Rate Limitting not working with React.

Closed this issue · 1 comments

Hello, I am greatfull to be using your services.

I have come accross an issue with rate limitting where I am using react to send emails to my address from a contact form. I wanted to limit the user so that they can only send an email every 15 seconds. I have written the sendEmail function like this:

const sendEmail = (evt: FormEvent<HTMLFormElement>) => {
	evt.preventDefault();
	if (!form.current) return;

	const email = emailjs.sendForm(
		import.meta.env.VITE_EMAILJS_SERVICE_ID,
		import.meta.env.VITE_EMAILJS_TEMPLATE_ID,
		form.current,
		{
			publicKey: import.meta.env.VITE_EMAILJS_PUBLIC_KEY,
			limitRate: {
				id: 'app',
				throttle: 1000 * 15,
			},
		}
	);

	toast.promise(email, {
		loading: 'Sending the Email Please Wait',
		success: () => 'Successfully Sent Your Email!',
		error: (err) => {
			console.error('err => ', err);
			return "Couldn't sent the email. Please try again.\n" + err;
		},
	});
};

The problem is that even if the user doesn't wait for the 15 second duration, the api sends the email regardless. I have tried not setting the id but it didn't change anything. Am I doing something wrong?

Thank you for your help.

@LoyalEnv0y Hi, thank you for your feedback. As far as I can see, the tests successfully pass this scenario.
Can you please provide a small example where we can reproduce this issue?

P.S. your code looks correct.