Authenticating with Firebase creates a 24 hour session for the user. This allows you to fetch the current session for the user, as well as logout the user and destroy the session.
Hello, this is Lukas Ruebbelke, and welcome to part two of two of the video series that I started showing you how to use the Firebase simple login service to handle user authentication in your AngularJS application.
We are going to extend the application that we created in the previous video to have logout functionality, as well as the ability to get the current logged in user.
By default login sessions last 24 hours on the Firebase side, so when you login and come back, it would be nice to get the currently logged in user so they don't have to login every single time.
Jumping into the code, we are going to create a method called "get current user," and we are going to use our login service to get the current user. This method returns a promise with the value of you guessed it, the current logged in user. We are going to go ahead and set the current user on scope to that value. Then let's call this method "to get things started."
I'm going to refresh the page, and you can see that I am logged in with this user right here. How do I actually log this user out? We are going to create another method called logout, where we are going to call logout on our login service and let's go ahead and set current user to null.
Let's refresh the page one more time. I'm still logged in, but I'm going to put logout. That cleared the current user as well as called log out on the Firebase side.
Let's refresh the page. You can see that I am not logged in anymore, so let me log in with a different user. You see that I'm logged in now with this user. Let me refresh the page, and you'll see that I was able to call and get current user, and get the current logged in user for this session.
Let's just review what I've done. I created a "get current user" method where I called get current user on the login service which will get the current logged in user for that session. I'm setting that user to scope that current user. Then I'm calling a logout on the login service to actually log that user out.
This concludes part two of two of this series of how to handle user authentication using the Firebase simple login service. Stay tuned for more videos. I'll catch you next time.