This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Firebase Basic Authentication Part 2

3:22 Angular 1.x lesson by

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.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

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.

Avatar
matthew

Can you please do a video on Authentication and fireangular? For example how would a Admin see a page differently than say just a subscriber.

In reply to egghead.io
Avatar
John

yes! please do a video on security rules! Stick with your CRUD example, how would we only show items created by the authenticated user? How about sharing specific items with other users?

In reply to matthew
Avatar
David

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?)

Avatar
Camrin

I would love to see this too!

In reply to John

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.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?