[React] Access displayName after createUserWithEmailAndPassword return null

1,251 views
Skip to first unread message

Mike

unread,
Feb 13, 2020, 7:23:20 PM2/13/20
to Firebase Google Group
Hi, I've faced some problem today, I'm trying to show a 'welcome {name}' message after the user register with createUserWithEmailAndPassword.
The problem is, the welcome message shows in component right after the login function is dispatched, and somehow the updateProfile is not done yet. It display null. When i refresh the page it works fine, and the message is showing correct name value. How can I improve it ?
My short code look like this

/* Create user */ 
firebase.auth().createUserWithEmailAndPassword(email, password, nickName)
                .then(() => {
                    const user = firebase.auth().currentUser;
                    user.updateProfile({
                        displayName: nickName
                    });
                 })
                .catch(e => {
                    console.log(e.code, e.message);
                });

/* which then fires the function */

firebase.auth().onAuthStateChanged((user) => {
    if (user) {
        store.dispatch(login(user.uid, user.displayName));
    } else {
        store.dispatch(logout());
    }
})

Kato Richardson

unread,
Feb 18, 2020, 11:52:12 AM2/18/20
to Firebase Google Group
Mike,

Profile updates do not affect auth tokens that are already issued. So you'll likely need to store the nick and use it locally for the new user at least on the first run.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/58b581f0-6a75-42e2-a364-63c90b6ee5a5%40googlegroups.com.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages