AngularJS and Firebase Authentication

I would like to add an authentication mechanism to my AngularJS application with a Firebase backend. The requirements are simple:

  • Authenticated users must have access to any page.
  • If /some_page go to /some_page (any page except /login ), they should be redirected to /login . When they enter the correct credentials, they should be redirected back to /other_page .

The possible solution described here makes the following assumption:

My solution assumes the following server-side behavior: for each / resources / * call, if the user has not logged in, respond to status 401

But I'm not sure if this behavior can be applied when using Firebase as a backend.

Any help and / or examples for implementing such integration with AngularJS + Firebase will be appreciated!

+4
source share
3 answers

One solution is to do your client-side routing using the $ route service.

When a user authenticates through Firebase, save a record of this on the client, for example, in localstorage, some comprehensive controller or your own Angular service (my preferred option).

In your routing controller, if the user is authenticated, redirect to /some_page , otherwise redirect to /login and track the $ location where the user should go.

If, on the other hand, you want to route your server, you can use the solution you are attached to by generating your Firehase auth tokens server .

+2
source

I had the same requirement recently and stumbled upon this blog post. http://www.42id.com/articles/firebase-authentication-and-angular-js/

It explains the creation of an Angular JS application that interacts with Firebase. Authentication methods are also included against OAuth providers such as Google+ and Github using the Firebase API, authentication-based routing, storing user profile information in Firebase, and setting up Firebase security rules to protect user data.

+1
source

If you use Firebase Simple Login (and do not generate authentication tokens on your own servers), you can see how to determine your client login base here: Displaying text after login

0
source

All Articles