我希望在手机验证之前验证firebase中存在的用户电话号码。如果用户存在,那么只有otp验证才会启动显示错误。请帮助我
答案 0 :(得分:0)
因此,您希望通过从管理面板输入来限制用户群。 如果是,那么如果输入no,则使用匿名身份验证来读取数据库。存在于数据库中,然后只继续手机验证并链接这些匿名和电话帐户。
答案 1 :(得分:0)
public class PhoneNumberAuthentication extends AppCompatActivity {
private static final int RC_SIGN_IN = 123;
@Override
protected void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseApp.initializeApp(this);
FirebaseAuth auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null) {
// already signed in
startActivity(new Intent(PhoneNumberAuthentication.this, MainActivity.class));
finish();
} else {
// not signed in
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(
Arrays.asList(
new AuthUI.IdpConfig.PhoneBuilder().build())).build(),
RC_SIGN_IN);
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// RC_SIGN_IN is the request code you passed into startActivityForResult(...) when starting the sign in flow.
if (requestCode == RC_SIGN_IN) {
IdpResponse response = IdpResponse.fromResultIntent(data);
// Successfully signed in
if (resultCode == RESULT_OK) {
startActivity(new Intent(PhoneNumberAuthentication.this, MainActivity.class));
finish();
} else {
// Sign in failed
if (response == null) {
// User pressed back button
//showSnackbar(R.string.sign_in_cancelled);
return;
}
if (response.getError().getErrorCode() == ErrorCodes.NO_NETWORK) {
// showSnackbar(R.string.no_internet_connection);
return;
}
// showSnackbar(R.string.unknown_error);
// Log.e(TAG, "Sign-in error: ", response.getError());
}
}
}}
还要添加build.gradle
implementation 'com.firebaseui:firebase-ui-auth:3.2.2'
答案 2 :(得分:0)
您可以使用Admin SDK按phoneNumber
查找用户:
admin.auth().getUserByPhoneNumber(phoneNumber)
这将帮助您检查具有此电话号码的用户记录是否已存在。
访问documentation了解详情。
您可以创建一个HTTP端点来执行此操作。