我有一个移动应用程序,其中通过电子邮件和密码注册用户可以正常工作。我要按如下所述进行更改。
我要使用他的电子邮件和电话号码注册用户,而无需指定密码。这是由系统管理员完成的。然后,在首次登录时,用户应该能够进行电话身份验证,然后设置密码。 firebase支持吗?如果是,有人可以指出我该怎么做吗?
答案 0 :(得分:0)
Create the user以及使用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支持的所有平台上完成。