How to check for a phone auth user in Android?

让人想犯罪 __ 提交于 2021-02-01 05:10:10

问题


How to modify this onStart() method to get my separate Phone auth user database?

@Override
protected void onStart() {
    super.onStart();
    FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
    if (firebaseAuth.getCurrentUser() != null) {
     if(what condition required to check for phone auth){
        startActivity(new Intent(EnterAs.this, UI_Main_User.class));
        finish();
    } else {
       for email auth users
    }
}

回答1:


You can do that by calling UserInfo's getProviderData() method on the FirebaseUser object, to get the list of all authentication providers that are used by the authenticated user. One more thing to note is that each UserInfo class contains a method named getProviderId() which returns the ID of the provider.

A workable solution in code might look like this:

FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
List<? extends UserInfo> userInfos = firebaseUser.getProviderData();
for (UserInfo userInfo : userInfos) {
    String providerId = userInfo.getProviderId();
    if (providerId.equals(PhoneAuthProvider.PROVIDER_ID)) {
        //Your logic goes here
    }
}

If in the future you'll use for example, Google authentication with Firebase, then you should check against:

GoogleAuthProvider.PROVIDER_ID


来源:https://stackoverflow.com/questions/61156122/how-to-check-for-a-phone-auth-user-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!