Summary

In this article, we will learn how to easily add “Guest User” functionality to your Firebase application without having to do any kind of large restructuring of your data model.

This article is meant for applications that manage user-specific data. A calculator app, for example, probably does not need user data and therefore is not applicable.

Background

Having a “Try as Guest” feature is something you should do for ANY and ALL apps that you create.

Whenever a user registers for a service and provides their email and password, they are paying a price: They are giving up a little bit of privacy and taking a risk in exchange for that service. Users don’t know how securely their data will be managed. And by registering for a service, they are trusting a company with some of their personal data.

I personally have had my email and password stolen from LinkedIn and Spotify. Those are both huge companies that should have the resources and knowledge to protect user data. So if they can be breached, why should we believe that an indy developer, or anyone else for that matter, can do any better?

Often times, this risk is worth it for the service that is being offered. But by not allowing users to try your product before registering, you are taking away their ability to decide whether they are willing to take that risk or not. And ultimately, some users will decide it’s not worth it and you will lose them.

There are several levels of access that can be provided, and I have outlined three of them below:

Access Level: No Access

This is the worst type of access. This is where users can’t get past the login/signup page without creating an account.

With this access level, users have no idea how the app works beyond screenshots and descriptions they may have seen on a website or app store.

For example, I recently found an app that describes itself as “a living travel journal.” It seemed like an interesting app that allows users to share photos and notes from trips they’ve taken. Unfortunately, upon downloading the app, I couldn’t get past the login page. Although the screenshots in the App Store looked good, it’s not quite the same as interacting with the app, and I decided not to create an account or to use the app.

“Sign Up” or “Log In” are the only options…

Access Level: Read-Only

This type of access allows users to see static content and the content of other users, but does not allow them to create their own content until they have created an account.

This is an acceptable form of access and is very easy to implement. However, if generating content is a large part of your app’s functionality, this type of access deprives users the experience of what it’s like to generate content on your app.

For example, YouTube allows users to watch videos without creating an account. But without an account, they won’t be able to subscribe to channels or upload their own videos.

Access Level: Guest Conversion

This type of access allows users to use every feature of the application, including generating content. Users access the app as an anonymous “guest” and if they decide they like the app and want to create an account, all of their content is transferred to the newly created account.

For example, I made an app once called Vint. Although the app no longer works, it allowed users to track their vehicle maintenance and mileage and would give reminders when scheduled maintenance was due.

Users could try the app out as a guest, and if they liked it, they could register with an email address so they could login again in the future. A banner at the top of the app constantly reminded them that they were logged in as a guest and would need to register if they wanted their data to be saved after exiting.

Even as a guest, I can document “Maintenance History.” A banner at the top informs me that I’m using a guest account.

I believe this type of access is the best as it allows users to fully preview your application before deciding if they’d like to use it. Fortunately, with Firebase Authentication, implementing this couldn’t be easier.

Implementation

Enable “Anonymous” Authentication

The first step is to enable “Anonymous” authentication on your Firebase project. This is as simple as flipping a switch.

Sign In Anonymously

Next, add a button that allows users to try your application as a guest. When the button is pressed, simply call the Firebase function:

firebase.auth().signInAnonymously()

Users will show up in the Firebase Authentication console and will have their own UID.

At this point, depending on how you’ve set up your app, users should be able to access and interact with it just as if they were logged in with any other authentication method. You may still want to restrict anonymous users from certain functions (like changing their password), so to determine whether an anonymous user is logged in, you can check:

firebase.auth().currentUser.isAnonymous

Convert the Account

Finally, provide users with the ability to convert their account to an account with a login and password. Otherwise, they may not be able to access the data they’ve generated as an Anonymous user once they’ve left the app. I recommend putting a banner at the top of the app reminding them that they are logged in as a guest.

When the user is ready to convert, first check if they are an Anonymous user. Then, generate a credential and link their account!

Conclusion

Strive to allow guest access to any app that you create. This will put your app a step above many others and your users will really appreciate this.

Resources

Video Tutorial