You might be knowing that Fabric is now acquired by Google and if you are using Fabric’s Digit for phone authentication (OTP sms verification) then you probably have received such email.
So its time to migrate from digit to firebase. Let’s get started.
You can find complete step by step instruction to migrate your digit app to firebase app here This instructions covers all aspects of migrating digit user accounts to firebase whether you have project on firebase console or not. I highly recommend to read all instructions carefully. It hardly take 2 minutes to read and 1 minute to perform. In our case after performing this steps we started getting our user data in firebase within 15 minutes.
You can skip step 1 and directly start from here only if you are not migrating from digit and just want to integrate firebase phone authentication in your app. At this step you must have project created on firebase console. If you have already added firebase to your android project, That’s fine. If not, then here are the instructions.
After adding firebase to your app you should enable phone authentication.
2.1 To enable it, Open project in Firebase console →Authentication → SIGN-IN-METHOD → click on phone → Enable
2.2 Add firebase ui auth dependency to app level build.gradle
// FirebaseUI Auth only compile 'com.firebaseui:firebase-ui-auth:2.0.1'
Some points to take care of –
you may need to add tools:replace=”android:value” to <meta-data> element of fabric api key like this and you are good to go.
<meta-data tools:replace="android:value" android:name="io.fabric.ApiKey" android:value="somekeyhere" />
2.3 Now replace Digit code with firebase code.
private static final int RC_SIGN_IN = 123; private FirebaseAuth auth;
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 == ResultCodes.OK) { Toast.makeText(this, "OTP verification success", Toast.LENGTH_SHORT).show(); return; } else { // Sign in failed if (response == null) { // User pressed back button Log.e("Login","Login canceled by User"); return; } if (response.getErrorCode() == ErrorCodes.NO_NETWORK) { Log.e("Login","No Internet Connection"); return; } if (response.getErrorCode() == ErrorCodes.UNKNOWN_ERROR) { Log.e("Login","Unknown Error"); return; } } Log.e("Login","Unknown sign in response"); } }
startActivityForResult( AuthUI.getInstance() .createSignInIntentBuilder() .setAvailableProviders( Arrays.asList( new AuthUI.IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER).build() )) .build(), RC_SIGN_IN);
2.4 Run the app. Done!!
If you see any error regarding App validation failed due to SHA-1 certificate while running app. Please add SHA-1 Fingerprint. To add it click on Gear icon besides overview(top-left side) in firebase console → Project setting → Scroll down → Add Fingerpint
Few advantages of using Firebase phone authentication –
Note: Process of migration will not affect your app or your app’s users in any way
You can find sample project here.
Thanks for reading this article. Please recommend this article if you found it helpful.
Also read: Customizing New Cupertino Widgets in Flutter: A Deep Dive