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

227
Vistas
Firebase v9 auth.currentUser is null after creating the user

Here's my JS code:

import { ref } from "vue"
import { projectAuth } from '../firebase/config'
import { getAuth, createUserWithEmailAndPassword, updateProfile } from 'firebase/auth'

const error = ref(null)
const isPending = ref(false)

const signup = async(email, password, displayName) => {
    error.value = null
    isPending.value = true

    try {
        const res = createUserWithEmailAndPassword(projectAuth, email, password)
        console.log(projectAuth.currentUser)

        if (!res) {
            console.log('Could not complete the signup')
            throw new Error('Could not complete the signup')
        }

        console.log(projectAuth.currentUser)
        await updateProfile(projectAuth.currentUser, {displayName})        
        error.value = null
        isPending.value = false

        return res
        
    } catch(err) {
        console.log('ERROR: ' + err.message)
        error.value = err.message
        isPending.value = false
    }
}

const useSignup = () => {
    return {error, signup, isPending}
}

export default useSignup

My Vue3 application is calling the signup function in this script whenever a user is signing up. The createUserWithEmailAndPassword function is successful and the user shows up in firebase. But I want to also add a display name to my user, so I'm trying to use the updateProfile function to do that but there's a problem.

The problem is the projectAuth.currentUser is null even after creating the user and I can't figure out why??

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The createUserWithEmailAndPassword() method returns a promise. Since your function is async, try adding await:

const res = await createUserWithEmailAndPassword(projectAuth, email, password)
console.log(projectAuth.currentUser)

Alternatively, you can pass User object to updateProfile directly from res:

const { user } = await createUserWithEmailAndPassword(projectAuth, email, password)

await updateProfile(user, { displayName })
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