LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code
JS
var ref = new Firebase("https://angularfire-uirouter.firebaseio.com");
var app = angular.module("sampleApp", [
  "firebase",
  "ui.router"
]);
app.factory("Auth", ["$firebaseAuth",
  function($firebaseAuth) {
    return $firebaseAuth(ref);
  }
]);
app.controller("MainCtrl", ["$scope", "Auth",
  function($scope, Auth) {
    $scope.auth = Auth;
    $scope.auth.$onAuth(function(authData) {
      $scope.authData = authData;
      console.log(authData);
    });
  }
]);
app.controller("NavCtrl", ["$scope", "Auth",
  function($scope, Auth) {
    $scope.auth = Auth;
    $scope.auth.$onAuth(function(authData) {
      $scope.authData = authData;
    });
  }
]);





// UI.ROUTER STUFF
app.run(["$rootScope", "$state", function($rootScope, $state) {
  $rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
    if (error === "AUTH_REQUIRED") {
      $state.go("home");
    }
  });
}]);
app.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise("/home");
  $stateProvider
    .state('home', {
      url: "/home",
      template: "

Home

This is the Home page

", resolve: { "currentAuth": ["Auth", function(Auth) { return Auth.$waitForAuth(); }] } }) .state('profile', { url: "/profile", template: "

Profile

This is the Profile page

", resolve: { "currentAuth": ["Auth", function(Auth) { return Auth.$requireAuth(); }] } }) });
Host Instantly Drag and Drop Website Builder

 

Term
Wed, 11/29/2017 - 11:27

Related Codes

Pen ID
Pen ID
Pen ID