在Firebase中无需身份验证就将电话号码存储在用户信息/用户个人资料中

时间:2018-07-26 14:26:51

标签: firebase react-native firebase-authentication expo

我正在使用Firebase上的Email / Password方法来吸引用户。我对切换到电话身份验证不感兴趣。话虽如此,我想将用户的电话号码存储在他们的个人资料中,以便以后访问。

我知道我可以这样存储它:

用户/ UID /电话号码:XXXXXX

但是我希望以后可以访问它而不必查询该用户ID。而是我想存储它,以便可以通过currentUser.phoneNumber或类似的东西来获取它。

我知道那里有一个displayName和profilePic的updateProfile,但是文档似乎不允许phoneNumber。反正有实现这一目标的方法吗?

2 个答案:

答案 0 :(得分:1)

无法使用户电话执行以下操作:

mAuth = FirebaseAuth.getCurrentUser().getPhoneNumber();

因为如果不实施Firebase Phone Auth,则无法直接访问用户电话。

由于您不必担心该号码是否来自该人,因此可以通过执行AlertDialogEditText来提示用户键入您要存储的所需号码,然后采用一种变通方法是的,由于您没有从Auth获取它,因此每次都需要查询它。

如您所说的那样在不查询数据库的情况下在userInfo中获取用户电话号码的唯一方法是实现Phone Auth。

答案 1 :(得分:0)

考虑使用admin sdk updateUser API:https://firebase.google.com/docs/auth/admin/manage-users#update_a_user

admin.auth().updateUser(uid, {
  phoneNumber: "+11234567890",
}).then(function(userRecord) {
  // User updated. You can now get this from client:
  // FirebaseAuth.getCurrentUser().getPhoneNumber();
}).catch(function(error) {
  // Error occurred.
});
相关问题