Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
limit execution of a function for specified user at one per minute

I have a route like this to execute a function:

router.post('/send-verification-again', sendVerificationAgain);

At the function above we have the email or phone number of the account in which we want to verify.

This will execute a function to send an email or sms to the user with his/her verification code ok?

Apparently we don't want the user to be able to send more than one request per minute to this route, right?

How can I limit execution of a function for specified user at one per minute?

function sendVerificationAgain(email) {
  // for each specific email here the function can be executed one time per minute
}

This is very common functionality, is there any convention to do this?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can simply store the email for a minute and check if it's stored:

const recentlySent = new Set();

function sendVerificationAgain(email) {
    if (recentlySent.has(email)) return;
    recentlySent.add(email);
    setTimeout(() => recentlySent.delete(email), 60e3);
    // ...
}

You might also want to first normalize the email, e.g. lowercase it.

For more information, look up "debounce" in the programming sense

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda