Firebase updateProfile的Promise是否返回用户?代码调用无返回值
关于Firebase Auth updateProfile Promise返回值的问题
没错,你猜的完全对!updateProfile方法的Promise确实不会返回任何用户对象,这就是你控制台里看不到user输出的原因。
Firebase Auth的这个设计其实很直观:updateProfile只是负责修改当前登录用户的资料,操作成功后它并不会把用户实例回传给你。因为更新完成后,firebase.auth().currentUser这个全局的用户对象已经同步更新了,你直接拿它用就行。
修改你的代码试试,这样就能看到更新后的用户信息了:
firebase.auth().currentUser.updateProfile({displayName: 'test'}) .then(() => { // 直接访问更新后的currentUser const updatedUser = firebase.auth().currentUser; console.log(updatedUser); }) .catch(err => { console.log(err); });
另外提醒一句:调用updateProfile之前一定要确保currentUser不是null哦,也就是要在用户已经登录的状态下执行这个操作,不然会抛出错误的。
内容的提问来源于stack exchange,提问作者Taylor Austin
相关产品推荐
相关产品推荐

