Artem Solovev Artem Solovev - 3 months ago 47
AngularJS Question

How to Authenticate Users in a similar way from Legacy Firebase? - NgRoute

Earlier (from legacy docs) we can use this construction and it works fine:

$routeProvider.when("/home", {
// the rest is the same for ui-router and ngRoute...
controller: "HomeCtrl",
templateUrl: "views/home.html",
resolve: {
// controller will not be loaded until $waitForAuth resolves
// Auth refers to our $firebaseAuth wrapper in the example above
"currentAuth": ["Auth", function(Auth) {
// $waitForAuth returns a promise so the resolve waits for it to complete
return Auth.$waitForAuth();
}]
}
})
.when("/account", {
// the rest is the same for ui-router and ngRoute...
controller: "AccountCtrl",
templateUrl: "views/account.html",
resolve: {
// controller will not be loaded until $requireAuth resolves
// Auth refers to our $firebaseAuth wrapper in the example above
"currentAuth": ["Auth", function(Auth) {
// $requireAuth returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
return Auth.$requireAuth();
}]
}


But since the recent Google IO (May 18, 2016), that documentation is now deprecated. How could I authenticate my users with new rules?

I need simple decisions instead of
$waitForAuth()
and
$requireAuth()
.

Answer

You're using AngularFire 1.x, which works with Firebase 2.x.

The new Firebase SDK is 3.x, and you'll need to use AngularFire 2.x for it.

There is a great migration guide for AngularFire 1.x to 2.x on the AngularFire web site.

From that guide it seems that you now need:

Old method         New method
$requireAuth() ->  $requireSignIn()   
$waitForAuth() ->  $waitForSignIn()
Comments