如何将其他信息添加到firebase.auth() [英] How to add additional information to firebase.auth()

查看:131
本文介绍了如何将其他信息添加到firebase.auth()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将额外的属性电话号码和地址添加到这个数据集?我已经使用 firebase.auth()来实现登录,注册和更新 / code>



登入

  // Email Login 
firebase.auth()。signInWithEmailAndPassword(email,password).then(
ok => {
console.log(Logged in User, ok.user);
},
error => {
console.log(email / pass sign in error,error);
}
) ;

注册

  //注册
firebase.auth()。createUserWithEmailAndPassword(email,password).then(
ok => {
console。 log(Register OK,ok);
},
error => {
console.log(Register error,error);
}

更新:

  //用户认证
firebase.auth()。onAuthStateChanged(函数(用户){
if(user){
$ scope。 data = user;
} else {
//没有用户,重定向到登录页面
}
});
$ b $ //保存函数
$ scope.save =函数(值){

$ scope.data.updateProfile({

displayName:Test User,
email:test@gmail.com,
/ *手机:123412341,
地址:Temp Address,* /
photoURL: (www.example.com/profile/img.jpg

))。then(function(){

//更新成功

},函数(错误){

//发生错误。

});

};


解决方案

据我所知,您必须管理如果您希望拥有比Firebase提供的默认用户更多的字段,则可以自行创建用户个人资料。



您可以在Firebase中创建引用来保留所有用户个人资料。

 用户:{
userID1:{
name:user 1,
gender:male
},
userID2:{
name:user 2,
gender:female


$ / code $ / code>来检测用户何时登录,如果是,可以使用 once()来检索用户的数据

  firebaseRef.child('users')。child(user.uid).once('value',callback)

希望有帮助


How can I add extra attributes phone number and address to this data set? It seems like Firebase documentation doesn't specify anything about that.

I have implemented the login, register and update using firebase.auth()

Login :

//Email Login
firebase.auth().signInWithEmailAndPassword(email, password).then(
   ok => {
        console.log("Logged in User",ok.user);              
    },
    error => {
        console.log("email/pass sign in error", error);
    }
);

Register:

 //Sign Up
firebase.auth().createUserWithEmailAndPassword(email, password).then(
    ok => {
        console.log("Register OK", ok);
    },
    error => {
        console.log("Register error", error);
    }
)

Update:

//User Authentication
firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    $scope.data=user;
  } else {
    // No user, Redirect to login page
  }
});

//Save Function
$scope.save=function(values){

    $scope.data.updateProfile({

      displayName: "Test User",
      email: "test@gmail.com",
     /* phone: 123412341,
      address: "Temp Address",*/
      photoURL: "www.example.com/profile/img.jpg"

    }).then(function() {

     // Update successful.

    }, function(error) {

     // An error happened.

    }); 

};  

解决方案

As far as I know, you have to manage the users profiles by yourself if you want to have more fields than the default user provided by Firebase.

You can do this creating a reference in Firebase to keep all the users profiles.

users: {
  "userID1": {
    "name":"user 1",
    "gender": "male" 
  },
  "userID2": {
    "name":"user 2",
    "gender": "female" 
  }
}

You can use onAuthStateChanged to detect when the user is logged in, and if it is you can use once() to retrieve user's data

firebaseRef.child('users').child(user.uid).once('value', callback)

Hope it helps

这篇关于如何将其他信息添加到firebase.auth()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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