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

122
Vistas
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 Respuestas
Responde la pregunta

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 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