在 Firebase 中未经身份验证将 phone 号码存储在用户 info/user 配置文件中
Storing phone number in user info/user profile without authentication in Firebase
我在 Firebase 上使用 Email/Password 方法吸引用户。我对切换到 phone 身份验证不感兴趣。也就是说,我想将用户 phone 号码存储在他们的个人资料中以供以后访问。
我知道我可以这样存储它:
Users/UID/PhoneNumber: XXXXXX
但我希望以后无需查询该用户 ID 即可访问它。相反,我想存储它,以便我可以通过 currentUser.phoneNumber 或类似的方式获取它。
我知道有 updateProfile 需要 displayName 和 profilePic,但文档似乎不允许 phoneNumber。有没有办法实现这个?
你不能让用户phone做这样的事情:
mAuth = FirebaseAuth.getCurrentUser().getPhoneNumber();
因为如果不实现 Firebase Phone Auth.
就无法直接访问用户 phone
由于您不关心该号码是否来自该人,解决方法是执行 AlertDialog
或 EditText
以提示用户键入您要存储的所需号码,是的,您每次都需要查询它,因为您不是从 Auth
.
获取它的
如您所说,无需查询数据库即可在 userInfo 中获取用户 phone 编号的唯一方法是实施 Phone Auth.
Doing the workaround there is no guarantee that the phone number
entered by the user is the right one
考虑使用管理 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.
});
我在 Firebase 上使用 Email/Password 方法吸引用户。我对切换到 phone 身份验证不感兴趣。也就是说,我想将用户 phone 号码存储在他们的个人资料中以供以后访问。
我知道我可以这样存储它:
Users/UID/PhoneNumber: XXXXXX
但我希望以后无需查询该用户 ID 即可访问它。相反,我想存储它,以便我可以通过 currentUser.phoneNumber 或类似的方式获取它。
我知道有 updateProfile 需要 displayName 和 profilePic,但文档似乎不允许 phoneNumber。有没有办法实现这个?
你不能让用户phone做这样的事情:
mAuth = FirebaseAuth.getCurrentUser().getPhoneNumber();
因为如果不实现 Firebase Phone Auth.
就无法直接访问用户 phone由于您不关心该号码是否来自该人,解决方法是执行 AlertDialog
或 EditText
以提示用户键入您要存储的所需号码,是的,您每次都需要查询它,因为您不是从 Auth
.
如您所说,无需查询数据库即可在 userInfo 中获取用户 phone 编号的唯一方法是实施 Phone Auth.
Doing the workaround there is no guarantee that the phone number entered by the user is the right one
考虑使用管理 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.
});