android - 使用电话和电子邮件注册 Firebase,然后在首次登录时设置密码
问题描述
我有一个移动应用程序,用户通过电子邮件注册和密码正常工作。我想改变它,如下所述。
我想用他的电子邮件和电话号码注册一个用户而不指定密码。这是由系统管理员完成的。然后在第一次登录时,用户应该能够进行电话身份验证,然后设置密码。 firebase 支持这个吗?如果是的话,有人可以指出我该怎么做吗?
解决方案
使用 Admin SDK创建具有电子邮件和电话号码的用户:
admin.auth().createUser({
email: 'user@example.com',
phoneNumber: '+11234567890',
});
然后,用户可以通过客户端 SDK 使用您的应用中的电话号码登录。登录时,您检查是否设置了密码。如果没有,您要求用户通过 设置密码updatePassword
。这是使用 JS SDK 的片段:
const phoneNumber = getPhoneNumberFromUserInput();
const appVerifier = new firebase.auth.RecaptchaVerifier(
'sign-in-button',
{
'size': 'invisible',
'callback': function(response) {
// reCAPTCHA solved, allow signInWithPhoneNumber.
onSignInSubmit();
}
});
firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
.then((confirmationResult) => {
// SMS sent. Prompt user to type the code from the message, then sign the
// user in with confirmationResult.confirm(code).
...
return confirmationResult.confirm(smsCode);
}).then((userCredential) => {
// Check if password exists.
if (!(userCredential.user.providerData[1] &&
userCredential.user.providerData[1].providerId === 'password')) {
// Ask user for the new password.
...
// Save the password.
return userCredential.user.updatePassword(password);
}
}).catch((error) => {
// Error; SMS not sent
// ...
});
以上可以在 Firebase 支持的所有平台上完成。
推荐阅读
- tailwind-css - Tailwind:space-*-* 类弄乱了我的整个设计?
- python - 使用 python 或/和 twurl 将媒体上传到 twitter api
- amazon-web-services - 拉取附加到 Amplify 的项目
- node.js - 如何列出节点 cron 的计划作业
- authentication - Google Analytics Embed API 403 错误请求的身份验证范围不足
- python - 如何在字符串中找到所有可能的连续三元组?
- javascript - 需要正则表达式来比较字符串中的最后一个数字
- php - 基于 Cookie 的身份验证 - 客户端
- github - 使用 github webhooks 配置成功/失败通知
- android - 如何在 Android 上实现应用内购买并处理一些逻辑以增加我的服务器上的积分?