has anyone come across an issue where verification emails get repeatedly sent out when refreshing th...
a
has anyone come across an issue where verification emails get repeatedly sent out when refreshing the verify-email page?
r
Hey! That’s actually intentional. But you can change the behaviour by overriding the recipe function that sends the email verification email to be rate limited.
Hey! That’s actually intentional
But you can change this bahaviour by overriding the frontend function that calls the api to send an email to be rate limited based on some value in localstorage that you set
a
ahh interesting, nice thats a good idea
thank you
r
Happy to help! It you need me to give you code snippets for how to do that, lmk
a
that would actually be super helpful
r
You can do something like this:
Copy code
ts
EmailPassword.init({
    override: {
        emailVerification: {
            functions: (oI) => {
                return {
                    ...oI,
                    sendVerificationEmail: async function (input) {
                        let lastEmailSentTime = localStorage.getItem("lastEmailSentTime");
                        if (lastEmailSentTime === null || Number(lastEmailSentTime) + 2000 < Date.now()) {
                            localStorage.setItem("lastEmailSentTime", Date.now() + "")
                            return oI.sendVerificationEmail(input);
                        }
                        return {
                            status: "OK",
                            fetchResponse: new Response() // some place holder.. doesn't matter
                        }
                    },
                }
            }
        }
    }
})
I assume you are using emailpassword recipe, but if not, the other recipes have something similar as well.
Note that this function also gets called when the user clicks on resend email on that screen. So whatever rate limit logic you have, would be applied to that button as well. That being said, this is a rare case where the user would keep on refreshing the page again and again.
2 Views