I watched a video on lynda, but unfortunately it's not on the latest version of the API.
The video shows how to use firebaseSimpleLogin, but this was changed to authWithPassword if I want a email & password type of authentication.
I can login, logout and register but the
PROBLEM is: I can't verify if the user is logged in or logged out.
here is my code below:
The Factory
GlobalCtrl.factory('Auth', ['$firebaseAuth', function($firebaseAuth){
var ref = new Firebase("https://taxiq-app.firebaseio.com"); //call on firebase database
//var objects = $firebase(ref) // reference database
return $firebaseAuth(ref);
}]);
The controller
taxiGlobalCtrl.controller('LoginController',['$scope','$firebase','Auth' ,'$location', function($scope, $firebase,Auth, $location){
$scope.login = function(){
Auth.$onAuth(function(authData) {
$scope.authData = authData;
console.log($scope.authData);
});
Auth.$authWithPassword({
email: $scope.username,
password: $scope.password
}).then(function(authData) {
console.log("Logged in as:", authData.uid);
$location.path('/tickets');
}).catch(function(error) {
console.error("Authentication failed:", error);
$scope.loginError = "loging error";
});
}
}]);
The naV that will show logout after logged in
<div>
<a class="navbar-brand" ng-href="#">Tiketa</a>
<ul class="nav navbar-nav">
<li ng-hide="authData"><a ng-href="#/login">Login</a></li>
<li ng-hide="authData"><a ng-href="#/register">Register</a></li>
<li ng-show="authData"><a ng-href="#/tickets">Tickets</a></li>
<li ng-show="authData"><a ng-href="#" ng-click="auth.$unauth()">logout</a></li>
</ul>
note: I'm fresh from online resources about angular and firebase,... I'm a noob