📞Phone Login with Firebase
Set up a user authentication system using Phone login with Firebase
Last updated
Set up a user authentication system using Phone login with Firebase
Last updated
This guide covers how to set up a login page in Bravo using Firebase as the user management service. where users introduce their phone number, and get a SMS with a code they need to use to log in.
What is Firebase? Firebase is a backend-as-a-service (Baas) from Google that provides features for building mobile apps.
Here's a sample design file that already contains all the necessary tags for this phone login feature. It contains the tags phone login and also email login. They can also be combined with Firebase's Social Login.
Make sure to place the flow start point (Figma) or Home icon (XD) on the "Home" screen of your app (i.e. the first screen users will see after they have logged in).
In order to set up the phone login, use the tags below:
[component:input-tel]
: Indicates which field will be used as the user phone input. It needs to be a valid phone number, or a test phone number provided in Firebase.
[action:login:firebase-phone]
: performs the login action, needs to be added in the login button.
In this Bravo Sample, we use other Firebase login options, if you're using only the phone option as login, add the [page:login]
tag to the login-phone
screen.
After the login screen, the user will navigate to a screen where they need to input a confirmation code sent by email.
You'll need to create a page where the user will introduce a confirmation code received via SMS. The user will automatically navigate to this page after the login screen.
To set it up, add the following tags:
[page:login:verify-phone]
: add this tag in the page-level component.
[component:input-number]
: This will create a numeric input field for the confirmation code.
[action:verify-phone:firebase]
: this action sends the confirmation code. If the code is correct, the user will navigate to the home page. Otherwise, an error message will be displayed, and the user will need to log in again.
For phone and social logins, there's no signup page - the login action will also create new accounts for first-time users.
Please note that phone logins are functional exclusively on the final versions of apps, either in the testing phase or when officially released. In Bravo Vision, you can engage in a simulation.
Once you have the UI ready, it's time to manage user authentication in your existing Firebase project. If you haven't created your Firebase project yet, follow the steps provided here.
After the project is created, click on Project Overview from the left menu and then select Authentication. Here is where your user accounts will be created and stored.
Go to Sign-in method tab and select Phone from the Native provider options.
Enable the phone toggle. As you'll see, you can add here some test phone numbers to log in - you'll need to provide a test confirmation code as well, that you'll be able to introduce in the login flow.
Enable Anonymous login and do not forget to save!
Now, you need to obtain the Firebase configuration files (GoogleService-Info.plist for iOS and google-services.json for Android) and upload them to Bravo.
The purpose of this configuration file is to create a link between our app and this Firebase project. So, if in the future, you want to connect to another Firebase project, you can do it by uploading a new Firebase configuration file in Bravo for each mobile platform (iOS and Android).
Depending on your needs, you can either:
Set up your Firebase Login for Bravo Vision (recommended for prototyping and testing)
Set up your Firebase Login for your live or published app (recommended for publishers)
In case you want to configure both Bravo Vision and live app for iOS and Android, you will need 4 files in total:
GoogleService-Info.plist for iOS Bravo Vision
google-services.json for Android Bravo Vision
GoogleService-Info.plist for iOS published app
google-services.json for Android published app
Here are the steps to follow if you want to get the configuration files for Bravo Vision:
If you don't have any app created in Firebase yet, follow the next steps as you need to create new Firebase configuration files to upload them to Bravo Studio.
Scroll down to Your apps section and click Add app.
Choose a platform (iOS or Android) and do the following depending on the platform:
Go to Project Overview (from the left menu), click the iOS symbol.
In step 1, fill in the iOS Bundle ID for Bravo Vision: com.codelesslabs.app
Leave the rest blank, and click Register app.
In step 2, download the file GoogleService-Info.plist and click, Next to continue.
The rest of the steps are not needed, so click Next for Steps 3 and 4.
To finish, in Step 5, click Continue to the console.
To verify that the app has been created, go to your Project Overview > General > Your apps.
Once having the Firebase configuration files, go back to Bravo Studio, open the App project that has the login (or import your design file if you haven't yet) and click on the Integrations tab.
Navigate to the Login option in the left-hand sidebar and Enable the Firebase toggle.
Once enabled, the Bravo Vision tab will be selected by default. Click on the Configure button to upload the Firebase files in the corresponding fields. It is also possible to do so from Firebase Config.
After uploading the files, do not forget to Save the changes. You must have a green check in order for that integration to work correctly on that platform you're setting up. If you're not setting up Firebase in a certain platform, you can ignore the warning icon.
Your app is ready to test! Open Bravo Vision to test out the login pages.
On Bravo Vision, every time the app is opened, login will be required. This won't happen on the published app, where the session will be maintained until the user chooses to log out.
After the user has logged in, a special variable will be created: ${user.id}
. This built-in variable can be sent as part of an API request, to handle user-specific data in the database.
Once you are ready to publish your app to the stores, you need to create new Firebase configuration files with the final bundle ID (for iOS) and package name (for Android) and upload them to Bravo Studio.
If you don't have any app created in Firebase yet, follow the next steps as you need to create new Firebase configuration files with the final bundle ID (for iOS) and package name (for Android) and upload them to Bravo Studio. Otherwise, add the missing params we mention:
Scroll down to Your apps section and click Add app.
Select a platform: iOS or Android.
Register the app and do the following depending on the platform:
Enter your Bundle ID
and App Store ID
. Remember you need to complete step 2 of the publishing process to have these parameters ready.
Where do I find the final Bundle ID (for iOS)?
When you have the necessary files for publication, use the same Bundle ID from the Bravo publication form for the final Firebase file. (Check how to set up the Bundle ID on the app publication process)
For iOS, you'll need to set up Cloud Messaging in Firebase. This is found under Project Settings > Cloud Messaging > Apple App configuration.
Cloud messaging allows to be configured using an APNs Authentication Key or using APNs Certificates. Using authentication key is recommended, and also easier to set up.
To do this, inside the Developer Central, go to Keys and create a new one, of type Apple Push Notifications service (APNs):
Fill the KeyID, TeamID and upload the p8 file in Firebase settings, and that's it. The TeamID is displayed in the Membership page.
Once having the Firebase configuration files, go back to Bravo Studio, select the App > Integrations tab > Firebase Config.
Under "Activate Firebase services for final app", upload the Firebase files in the corresponding fields and do not forget to Save the changes.
Firebase integration has been updated in this app. Please request a new build and upload a new version to ensure your published app continues to work properly.
In case you already have a published app bundle, and you change these Firebase assets, you'll need to generate a new bundle and publish an update to the stores.
Once completed, your app's login is ready to test! Open Bravo Vision or your Published app to test out the login pages.