我相信这是可能的,尽管它会有点棘手。您将必须同时实现 email 和 phone number 并在回调中添加一个检查以查看两者是否在用户登录之前都已完成。我认为鉴于电子邮件似乎必须让用户登录,您将不得不实施电话验证首先在电子邮件之前进行,并在检查电子邮件和登录之前添加一个电话已验证的检查。显示在文档中:
按照文档中的说明设置电话验证和回调
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential credential) {
// This callback will be invoked in two situations:
// 1 - Instant verification. In some cases the phone number can be instantly
// verified without needing to send or enter a verification code.
// 2 - Auto-retrieval. On some devices Google Play services can automatically
// detect the incoming verification SMS and perform verification without
// user action.
Log.d(TAG, "onVerificationCompleted:" + credential);
//signInWithPhoneAuthCredential(credential); //send email for email verification here instead/ sign in with email method
}
这样确认电话号码后,可能会发送电子邮件验证
//Save the user email address beforehand for this
FirebaseAuth auth = FirebaseAuth.getInstance();
auth.sendSignInLinkToEmail(email, actionCodeSettings)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "Email sent.");
}
}
});
实现此https://firebase.google.com/docs/auth/android/email-link-auth#completing_sign-in_in_an_android_app 以设置动态链接以在应用内完成登录
并有类似的东西用于使用电子邮件方法登录。
FirebaseAuth auth = FirebaseAuth.getInstance();
Intent intent = getIntent();
String emailLink = intent.getData().toString();
// Confirm the link is a sign-in with email link.
if (auth.isSignInWithEmailLink(emailLink)) {
// Retrieve this from wherever you stored it
String email = "someemail@domain.com";
// The client SDK will parse the code from the link for you.
auth.signInWithEmailLink(email, emailLink)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "Successfully signed in with email link!");
AuthResult result = task.getResult();
// You can access the new user via result.getUser()
// Additional user info profile *not* available via:
// result.getAdditionalUserInfo().getProfile() == null
// You can check if the user is new or existing:
// result.getAdditionalUserInfo().isNewUser()
} else {
Log.e(TAG, "Error signing in with email link", task.getException());
}
}
});
}
我认为有更好的方法来解决这个问题。也许控制台中有某种云功能,但这是我目前能找到的唯一方法。