Get User Auth Profile Info in Firebase using Angular2

匿名 (未验证) 提交于 2019-12-03 09:52:54

问题:

Can you help me? I can't get the user's profile information in Angularfire Authentication like their facebook's profile picture or facebook name. Please help. Thanks a lot!

I've tried this code but its not working. I use Angular 2 TypeScript.

var user = firebase.auth().currentUser; var name, email, photoUrl, uid;  if (user != null) {   name = user.displayName;   email = user.email;   photoUrl = user.photoURL;   uid = user.uid;  // The user's ID, unique to the Firebase project. Do NOT use                    // this value to authenticate with your backend server, if                    // you have one. Use User.getToken() instead. }

回答1:

When you are using Angularfire2 this should be the way:

constructor(public af: AngularFire) {     this.af.auth.subscribe(auth => {      //Here you get the user information      console.log(auth));     }   }   login() {     this.af.auth.login({       provider: AuthProviders.Facebook,       method: AuthMethods.Popup,     });   }

Take a look here for more information: https://angularfire2.com/api/



回答2:

As you can see here in the Example app section, you can use auth.subscribe to detect the auth state:

export class myClass {   constructor(public af: AngularFire) {     this.af.auth.subscribe(auth => {         if(auth) {             console.log('You are authenticated', auth)         } else {             console.log('You are not authenticated')         }      });   } }


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