本文介绍了Firebase:使用phoneNumber重新验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以使用这样的电子邮件重新进行身份验证.
I know that I can reauthenticate with email like this.
var user = firebase.auth().currentUser;
var credentials = firebase.auth.EmailAuthProvider.credential(
user.email,
'yourpassword'
);
user.reauthenticateWithCredential(credentials);
但是,如果我使用phoneNumber作为登录方法,该如何重新认证?
But how can I reauthenticate if I use phoneNumber as my sign in method?
推荐答案
它与您使用电话号码登录的方式非常相似.您可以通过2种方式做到这一点:
It is very similar to how you sign in with phone number. You can do it in 2 ways:
使用reauthenticateWithPhoneNumber
:
const recaptchaVerifier = new firebase.auth.RecaptchaVerifier(
container, parameters, firebase.app());
recaptchaVerifier.render();
user.reauthenticateWithPhoneNumber(user.phoneNumber, recaptchaVerifier)
.then((confirmationResult) => {
return confirmationResult.confirm(prompt('Enter your SMS code'));
})
.then((userCredential) => {
// User successfully reauthenticated.
});
使用reauthenticateWithCredential
:
const recaptchaVerifier = new firebase.auth.RecaptchaVerifier(
container, parameters, firebase.app());
recaptchaVerifier.render();
const phoneAuthProvider = new firebase.auth.PhoneAuthProvider(auth);
phoneAuthProvider.verifyPhoneNumber(user.phoneNumber, recaptchaVerifier)
.then((verificationId) => {
const credential = firebase.auth.PhoneAuthProvider.credential(
verificationId, prompt('Enter your code'));
return user.reauthenticateWithCredential(credential);
})
.then((userCredential) => {
// User successfully reauthenticated.
});
这篇关于Firebase:使用phoneNumber重新验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!