Firebase Basic Authentication Part 2

Lukas Ruebbelke
InstructorLukas Ruebbelke
Share this video with your friends

Social Share Links

Send Tweet
Published 10 years ago
Updated 5 years ago

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.

Lukas Ruebbelke: [00:00] 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.

[00:17] 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.

[00:31] 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.

[00:45] 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."

[01:28] 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.

[02:11] 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.

[02:23] 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.

[02:47] 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.

[03:09] 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.

~ 10 years ago

I'm throwing my name into the hat as well, I'd love to see authentication with angular fire expanded to explain ACL's as well as complete low level examples (i.e. what happens when the credentials are incorrect or there's no user returned for getcurrentuser?)

Markdown supported.
Become a member to join the discussionEnroll Today