In Firebase, how do you update the user's displayName field in Auth?

I currently have a function that creates a user account. I would also like to add a username field, but I cannot figure out how to update it. I noticed in the Google console that there is a displayName field that is set to null. I do not know how to change this. This is what I have:

function create(email, password, username) {
    firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
        $timeout(function() {
            var errorCode = error.code;
            var errorMessage = error.message;
            console.log(errorCode.toUpperCase() + ":" + errorMessage);
        })
    });
    firebase.auth().onAuthStateChanged(function(user) {
        if (user) {
            $timeout(function() {
                console.log("Success! Account Created!");
                user.displayName = username; /* this doesn't work*/
            });
        } else {}
    });
}
+4
source share
1 answer

firebase.auth.Authgives you firebase.User. You should check the methods you can run at User: https://firebase.google.com/docs/reference/js/firebase.User

, updateProfile: https://firebase.google.com/docs/reference/js/firebase.User#updateProfile

+4

Source: https://habr.com/ru/post/1655275/


All Articles