Learn how to integrate Arengu with your own Firebase project, leveraging their user management APIs and creating a full authentication flow in a few steps.
In the Firebase console for your project, enable the "Email/Password" sign-in provider in Build > Authentication > Sign-in method.
If you don't have an app registered in your project, go to the project settings (the cogwheel icon, next to "Project Overview"), in the "General" tab and register a new web app by clicking on the </> button.
Give it any name, and unless you are using it, don't enable the "Set up Firebase hosting for this app" checkbox, we won't be using that.
You'll be presented with a snippet of code. Save it somewhere as we'll be using later and click on "Continue to console".
Lastly, in the "Service accounts" tab and under "Firebase Admin SDK", click on the "Generate new private key" button. A JSON file will be downloaded, keep it for later!
In Arengu, click on your profile button in the lower left corner and then on the "Vault" option.
Click on the "Add connection" button and choose "Firebase". Then, select the JSON file you downloaded from the Firebase console earlier, in the preparation step. The 3 fields will be automatically filled:
Click on "Continue" and give the connection a meaningful name. Finally, complete the connection with the "Add connection" button. Now you can use all the Firebase actions on your project from all Arengu flows.
In the forms module, create a new form to your liking. We'll be needing only one step, containing at least:
An email field:
A password field:
A Next button.
Now we need to build some logic to handle the data the user will submit in the form and generate the token Firebase needs to actually log the user in.
Add a new next step flow to the form we just created and set it up this way:
This action tries to get the user from the database of your Firebase project, using the email that the user entered in the form. Set it up like this:
If the previous lookup was successful (i.e. its result had a value), that means that email was already registered and we'll stop with an error message. We can check this with an if/then condition configured this way:
If the user does not exist, create the user in Firebase with the sign up action, using the email and password from our form. Configure the 'Sign up' action with these settings:
What about the 'Mark email as verified' checkbox? Note that — because we want to keep this tutorial short — we're skipping a very important step, which is verifying that the email address actually exists. But don't worry, you can do that easily in Arengu too. Just head over to our guide about email OTP flows.
The sign up action returned a unique random identifier for the user we just created. We'll be using that in the 'Issue a token' action, so Firebase gives us back a secure token that we will use to actually log in the user.
Set the action up like this:
The previous action returned a secure token that we have to make available in the ending screen of the form.
In order to do that, use the ‘Store state variable’ action configured this way:
Finally include a ‘Submit the form’ action, which does not need to be configured, and publish the changes.
Go back to the form editor in Arengu, open the form and click on the ending screen. Enable the ‘User session’ option and configure it as follows:
You can also configure the redirection URL, a thank you message to display in the form, and a JS callback. Once everything is set up, publish the changes and click on the Preview button to test it.
When logging in the user, our SDK assumes that the Firebase SDK has been already initialized. Make sure you do it or both your application and the form will not work properly.
Click on the 'Embed' tab at the top of the editor, choose the type of web app you're integrating Arengu with, and follow the instructions there. They are most often just copying a couple of lines of HTML.
Remember that Firebase, when a user logs in, attaches the session to the current host, so your form has to be embedded in the same host as your application.