使用Angular2在Firebase中获取用户身份验证配置文件信息 [英] Get User Auth Profile Info in Firebase using Angular2

查看:143
本文介绍了使用Angular2在Firebase中获取用户身份验证配置文件信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能帮我吗?我不能在Angularfire身份验证中获取用户的个人资料信息,比如他们的Facebook的个人资料图片或Facebook名称。请帮忙。非常感谢!



我试过这个代码,但是它不工作。我使用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; // Firebase项目所特有的用户ID。不要使用
//这个值来验证你的后端服务器,如果
//你有一个。使用User.getToken()来代替。


解决方案

> Angularfire2 应该是这样的:

 构造函数(public af:AngularFire){
this。 af.auth.subscribe(auth => {
//这里你得到用户信息
console.log(auth)); $ {
}
}
login(){
this.af.auth.login({
provider:AuthProviders.Facebook,
method:AuthMethods.Popup ,
});

$ / code>

查看更多信息: https://angularfire2.com/api/


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.
}

解决方案

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/

这篇关于使用Angular2在Firebase中获取用户身份验证配置文件信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆