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

156
Visualizações
Is it a bad practice to use Promise just to chain the excecution in the proper sequence?

I'm developing an app with a Sign In with Google Firebase. I've got the need to update de current user data wich exists within a Auth Module when a user sign in, and then chain the execution of stuff with that specific data. Something like this :

fbAuth.signInWithGoogle()
.then(()=>{
    let user = fbAuth.getCurrentUser()
    console.log(user);
    fbFirestore.postDocToExistingGroup("projects", user.uid, {user: user.uid, test:true})
})

So I coded the function as a Promise inside a module Pattern function named fbAuth, but it seems to not be the best way for me:

const signInWithGoogle = function(){
        return Promise.resolve(
            signInWithPopup(auth, provider)
            .then((result) => {
            // This gives you a Google Access Token. You can use it to access the Google API.
            const credential = GoogleAuthProvider.credentialFromResult(result);
            const token = credential.accessToken;
            // The signed-in user info.
            const user = result.user;
            setCurrentUser(user)
            console.log("Signed In", user)
            // ...
            }).catch((error) => {
            // Handle Errors here.
            const errorCode = error.code;
            const errorMessage = error.message;
            // The email of the user's account used.
            const email = error.email;
            // The AuthCredential type that was used.
            const credential = GoogleAuthProvider.credentialFromError(error);
            // ...
            })
        )
    }

I did that just to be sure that I've got the current user data to execute the rest of the code using that data and not because the function its suposed to be a Promise from the beginning.

about 4 years ago · Juan Pablo Isaza
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