简体   繁体   中英

Firebase Authentication Retrieve displayName Null

Why displayName is not null in authUser but retrieve null? However, after refreshing the page, then it will show the displayName that I have updated.

useEffect(()=>{
    const unsubscribe = auth.onAuthStateChanged((authUser)=>{
      if(authUser){
        //user has logged in
        setUser(authUser);
        console.log(authUser);
        console.log(authUser?.displayName);
        db
          .collection("users")
          .doc(authUser.uid)
          .get()
          .then((doc)=>{
            if(doc.exists){
              db
                .collection("users")
                .doc(authUser.uid)
                .get()
                .then((doc)=>{
                  setProfilePicture(doc.data().imageUrl);
                })
          }
          });
      }else{
        //user has logged out
        setUser(null);
      }
    })
    return ()=>{
      //perform some cleanup actions
      unsubscribe();
    }
  },[user, username]);

在此处输入图片说明

why you are using authUser?.displayName although you have checked already if the authUser object is null or not . may be you can try removing it . Or can you please provide the whole authUser object instead of screenshot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM