After successfully implementing the code below in the loginCtrl controller and login.html, I encountered some issues with setting up the workflow correctly. My goal is to achieve something like this:
//check if the current $scope has authData
//if so redirect to (or render) home.html
//if not stay on the login page.
I am new to Angular and still trying to figure things out. In Node.js with Express, it was clear to me that I just needed to render or redirect when the received data was good. But handling this in Angular seems confusing.
Javascript
.controller('loginCtrl', function ($scope, Auth, Login) {
$scope.login = function() {
Auth.$authWithOAuthPopup("facebook")
.then(function(authData){
console.log(authData);
})
.catch(function(err){
if(err) {
console.log("Authentication failed!!", err);
}
})
};
})
.factory('Auth', function($firebaseAuth){
var usersRef = new Firebase("https://dazzling-heat-4971.firebaseio.com/users");
return $firebaseAuth(usersRef);
})
HTML
<ion-content class="padding loginbox">
<div ng-hide="!authData" ng-click="login('facebook')">
<!-- <a ui-sref="home" ng-if="verifyLogin()"> -->
<button class="button button-positive icon ion-social-facebook">
Login with Facebook
</button>
<!-- </a> -->
</div>
</ion-content>