How to update user's profile after Firebase 9.0.0

In previous versions, you could update the Firebase user's profile information as follows:

js
import firebase from 'firebase/app'

const loginAndUpdate = async () => {

    // Getting user's object
    let { user } = await firebase.auth().signInAnonymously()

    // Updating user's profile using the updateProfile method
    await user.updateProfile({
        'displayName': 'erik',
        'photoURL': 'erik.jpg'
    })

}

After upgrading to Firebase 9.0.0, you selectively import the required functions:

js
import { getAuth, updateProfile } from 'firebase/auth'

const loginAndUpdate = async () => {

    // Calling authentication function
    let auth = getAuth()

    // You need to pass the authentication instance as param
    let { user } = await signInAnonymously(auth)

    // Passing user's object as first param and updating it
    await updateProfile(user, {
        'displayName': 'erik',
        'photoURL': 'erik.jpg'
    })

}

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.