Skip to content

Instantly share code, notes, and snippets.

@AngelEyesChina
Created January 1, 2015 15:42
Show Gist options
  • Save AngelEyesChina/de16e376a5eef17102b1 to your computer and use it in GitHub Desktop.
Save AngelEyesChina/de16e376a5eef17102b1 to your computer and use it in GitHub Desktop.
AngularFire 0.9.0 auth
<html ng-app="sampleApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="https://cdn.firebase.com/js/client/2.0.4/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/0.9.0/angularfire.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="SampleCtrl">
<div ng-show="user">
<p>Hello, {{ user.facebook.displayName }}</p>
<button ng-click="auth.$unauth()">Logout</button>
</div>
<div ng-hide="user">
<p>Welcome, please log in.</p>
<button ng-click="auth.$authWithOAuthPopup('facebook')">Login</button>
</div>
</body>
</html>
var app = angular.module("sampleApp", ["firebase"]);
// let's create a re-usable factory that generates the $firebaseAuth instance
app.factory("Auth", ["$firebaseAuth", function($firebaseAuth) {
var ref = new Firebase("https://<replace-with-your-db-id>.firebaseio.com/");
return $firebaseAuth(ref);
}]);
// and use it in our controller
app.controller("SampleCtrl", ["$scope", "Auth", function($scope, Auth) {
$scope.auth = Auth;
$scope.user = $scope.auth.$getAuth();
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment