Implementing anonymous authentication
You might wonder why we need this. Since it's anonymous, it means that we don't have an identity on our system. That is true, but sometimes we want to have protected content that we deliver to our authorized users. So by using this method, we allow non-users to have a temporary account to experience the app. But if they, for instance, decide to create an account, we can provide them the option of linking their sign-in account to an anonymous one.
How to do it...
- In order to do this, we will use the Firebase auth APIs like we did previously, as shown in the following code snippet:
//Get a button reference. let anonLogin = document.getElementById('anonymousLogin'); anonLogin.addEventListener('click', () => { firebase.auth().signInAnonymously() .catch(err => { //Catch and showcase the error. }); }, false);
- Now, we need another way to check whether the user is logged in or not. To do...