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

126
Visualizações
Firebase V9 Online Status

I'm trying to reconfigure some Firebase v8 code to firebase v9 in React... On a login/register page, I want to change the online status to true.

I'm not sure if this line of code will be much different or quite literally the same with updated variable names. This may be a very simple question (hopefully). I know in v9 a lot of these types of things are restructured with an import statement of a function already available in the firebase library. IDK if this is one of those things... :/. Thanks for your time! Let me know in advance if I need to include more of the code to make sense...

old (working) v8 code:
variables:

  • projectAuth = firebase.auth()
  • projectFirestore = firebase.firestore()

focusing on the line just below: "// set online to be true" ...within the login / register page:

try {
  // login
  const res = await projectAuth.signInWithEmailAndPassword(email, password)

  //set online to be true
  await projectFirestore.collection('users').doc(res.user.uid)
    .update({ online: true })

    // dispatch login action
  dispatch({ type: 'LOGIN', payload: res.user })

  if (!isCancelled) {
    setIsPending(false)
    setError(null)
  }
}    

My v9 Code:
variables:

  • auth = getAuth()
  • db = getFirestore()
    try {
      // login
      await signInWithEmailAndPassword(auth, email, password)
      .then((res) => {

        // dispatch login action
        dispatch({ type: 'LOGIN', payload: res.user })

        //set online to be true
        await projectFirestore.collection('users').doc(res.user.uid)
          .update({ online: true })
        
        if (!isCancelled) {
          setIsPending(false)
          setError(null)
        }
      })
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There's a top level function updateDoc() to update documents:

import { updateDoc, doc } from "firebase/firestore";

const docRef = doc(db, "users", res.user.uid)

await updateDoc(docRef, { online: true });
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