Get firebase.auth().currentUser with async/await

北城余情 提交于 2019-12-06 05:17:50

The equivalence of setInterval is : //calling the asynchronous function waitForCurrentUser(function(uid){ if(uid) console.log('the user id is',uid) })

   async waitForCurrentUser(userIdIs){

    try {
       let uid = await firebase.auth().currentUser.uid;
       if(uid)
       {
         clearInterval(waitForCurrentUser);        
         this.setState({uid});
         userIdIs(uid); 
       }
       else {
       console.log('Wait for it');
      }

    }

    catch(e){
     console.log(e)
    }

  //  return userIdIs(uid);//returns promise
  };

Cheers :)

async getUid() {
        let user = await firebaseApp.auth().currentUser;
        let email = await user.uid;
}

Hope it's usefull for you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!