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

214
Visualizações
How to pass post submit callback to authentication method

I'm implementing a user comments feature, and I'd like to allow users to start writing before asking for authentication to reduce UX friction.

The user flow would be:

  1. The user clicks on the input field, and start typing.
  2. Once done, the user clicks on the submit button, then the system will check if the user is authenticated.
  3. (A) If the user is logged in, then it will submit the content. (B) If the user is not logged in, open a login/signup modal.
  4. (A) If the user has an account, they choose login methods either email or social login. (B) If the user is new, they signup for a new account with either email or a social account.
  5. Once the user is authenticated, the authentication modal will close, and the content will then be submitted. (the user does not need to click on the submit button once again)

I think this is a very common use case, but I cannot find anything on Stackoverflow, or on Google search.

I'm using React with Firebase authentication. My first attempt is to check every second if the user is authenticated.

const submit = async (data) => {
  if (!isAuthenticated) {
    setOpenAuthDialog(true);
    while (!isAuthenticated)
      await new Promise((resolve) => setTimeout(resolve, 1000));
  }
  setDoc(doc(firestore, "comments", postId), data);
  setInputField("");
};

However, I don't feel this is the best practice, because it will continue to check even when the user abandons the authentication flow.

I think using callbacks might be the better approach, but the authentication modal and comments are sibling components. I'm not sure if passing the callback function to the sign-in methods is possible.

Please let me know if there is an any better approach to this problem.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

One way to do it with callbacks could be:

const submit = async (data) => {
    if (!isAuthenticated) {
        setOpenAuthDialog(true);
        setDataWaitingForSubmission(data)
        return;
    }
    setDoc(doc(firestore, "comments", postId), data);
    setInputField("");
}

// This is passed as callback to auth modal 
const onAuthSuccess = () => {
    if (dataWaitingForSubmission && isAuthenticated) {
        submit(dataWaitingForSubmission)
    }
}
about 4 years ago · Juan Pablo Isaza 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