Anonymous Sign-In allows users (who haven't signed up yet) to use your app without creating an account.
Anonymous sign in demo
Before getting started with this section, ensure you have:
- Completed Initial setup required for authentication. (Please note: Skip if you have already enabled authentication and created user collection while creating your project with Firebase Setup.)
Adding Anonymous Sign-In comprises of following steps:
To enable Anonymous authentication in the Firebase:
- Click on the Get started button.
- Select the Sign-in method tab.
- Click on Anonymous (Under Native Providers section). If you have already added any other provider, click on the Add new provider and then click on Anonymous.
- Find the Anonymous switch and enable it.
- Click on the Save button.
Enabling anonymous authentication in Firebase
To allow users to authenticate anonymously, you need a login page with a button. You can use one of our templates or create a page from scratch.
To create a new page from scratch:
- Click on the Select Page or Component from the Navigation Menu (left side of your screen).
- Click on + Create New and give it a name.
- Click on the + Create New button under the Blank Page template.
- Click on the Widget Tree from the Navigation Menu.
- Add the Button widget from the Base Elements tab (in the Widget Panel) or add it directly from the widget tree.
- Move to Property editor (on the right side of your screen) scroll down to the Alignment section. Bring the button in the center by adjusting the slider or directly entering the value.
- Find the Width property (under Button Style) and change it to 230
- Scroll down the Button Text section and change the Text to Anonymous.
- Scroll down to find the Icon section. Click on the None button and then search and select icon name with person.
Creating a page with anonymous sign in
To add an action to log-in Anonymously:
- Select the Button (with Anonymous text) from the widget tree or from the canvas area.
- Click on the Actions tab (on the right side of your screen).
- Click on + Add Action and select the On Tap option.
- Find the Action Type dropdown and change it to Authentication.
- Find another Action Type dropdown below, and change it to the Login.
- Click on the Auth Provider dropdown and set it to Anonymous.
- Now, checkmark the Create User Document checkbox.
- From the Collection dropdown below, select the users collection.
Adding an action to log in anonymously
To log out a user, you can place a button inside your home page and add the Logout action.
You can test the authentication on a device/emulator as well as in Run Mode. To use Run Mode, make sure you have completed Firebase setup.
To test authentication in Run Mode:
- Click on the Run button (top right corner of your screen)
- Click on the Anonymous button to log in anonymously.
- Click on the Logout button.
Testing anonymous sign in