Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda