Reputation: 3262
I looked at the FirebaseUI sign-in methods. on the first page of the explanation there is a "Sign in with a pre-built UI" as shown here: Easily add sign-in to your Android app with FirebaseUI. This page contains the following code:
// Choose authentication providers
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.PhoneBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build(),
new AuthUI.IdpConfig.FacebookBuilder().build(),
new AuthUI.IdpConfig.TwitterBuilder().build());
// Create and launch sign-in intent
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN);
And then
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
IdpResponse response = IdpResponse.fromResultIntent(data);
if (resultCode == RESULT_OK) {
// Successfully signed in
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
// ...
} else {
// Sign in failed. If response is null the user canceled the
// sign-in flow using the back button. Otherwise check
// response.getError().getErrorCode() and handle the error.
// ...
}
}
}
But, when I look at their example of the how to authenticate with phone via SMS, this code is no where to be seen, yet the verification works. The phone authentication code can be seen in their snippet: PhoneAuthActivity.java
So when do I need to use this code and when not? What is the purpose of this part?
Upvotes: 0
Views: 340
Reputation: 598765
There are two main ways to implement Firebase Authentication:
The first snippet you showed configures FirebaseUI, specifically saying what providers (Google, Facebook, Email+Password, Phone, Twitter) are enabled and then starting an activity to kick off the flow.
The second snippet uses the Firebase Authentication API directly to implement a part of the authentication flow.
If you're using FirebaseUI, follow the documentation for configuring phone number auth in its repo. As far as I can see there, this doesn't require the onActivityResult
you shared. Most likely that flow is already encapsulated in FirebaseUI itself.
Upvotes: 2