Advertisement
Guest User

Untitled

a guest
Oct 18th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. angular.js:13642TypeError: Auth.$requireAuth is not a function
  2. at $routeProvider.when.when.resolve.currentAuth (app.js:129)
  3. at Object.invoke (angular.js:4708)
  4. at angular-route.js:631
  5. at Object.q [as forEach] (angular.js:336)
  6. at n (angular-route.js:628)
  7. at angular.js:16104
  8. at m.$eval (angular.js:17378)
  9. at m.$digest (angular.js:17191)
  10. at m.$apply (angular.js:17486)
  11. at HTMLHtmlElement.<anonymous> (angular.js:13391)(anonymous function)
  12. @angular.js:13642
  13.  
  14. var app = angular.module("app", ["firebase", "ngRoute"]);
  15.  
  16.  
  17. app.factory("Auth", ["$firebaseAuth", "$rootScope", function($firebaseAuth) {
  18. var authRef = $firebaseAuth();
  19. return authRef;
  20. }]);
  21.  
  22.  
  23. app.controller("LoginCtrl", ["$scope", "Auth", "$location", function($scope, Auth, $location) {
  24. $scope.auth = Auth;
  25. $scope.user = $scope.auth.$getAuth();
  26.  
  27. var isNewUser = true;
  28. //signup
  29. $scope.signUp = () => {
  30. isNewUser = true;
  31. //Get Email and Password
  32. // TODO: Check for real email
  33. const email = $scope.loginEmail;
  34. const pass = $scope.loginPassword;
  35. const auth = firebase.auth();
  36. // Sign in
  37. auth.createUserWithEmailAndPassword(email, pass);
  38.  
  39. $scope.loginEmail = "";
  40. $scope.loginPassword = "";
  41.  
  42. $scope.loginFormShow = false;
  43. $scope.logoutFormShow = true;
  44.  
  45. $location.path('/home');
  46. };
  47. //set up user profile data
  48. firebase.auth().onAuthStateChanged(firebaseUser => {
  49.  
  50. if (firebaseUser && isNewUser) {
  51.  
  52. firebase.database().ref().child("userProfiles").child(firebaseUser.uid).set({
  53.  
  54. name: firebaseUser.email,
  55. role: "user",
  56. tags: "tags"
  57. });
  58.  
  59. }
  60. });
  61.  
  62. //login
  63. $scope.login = () => {
  64.  
  65. isNewUser = false;
  66.  
  67. const email = $scope.loginEmail;
  68. const pass = $scope.loginPassword;
  69. const auth = firebase.auth();
  70.  
  71. auth.signInWithEmailAndPassword(email, pass);
  72. //promise.catch(e => console.log(e.message));
  73.  
  74. $scope.loginEmail = "";
  75. $scope.loginPassword = "";
  76.  
  77. $scope.loginFormShow = false;
  78. $scope.logoutFormShow = true;
  79.  
  80. $location.path('/home');
  81. };
  82.  
  83. //logout
  84. $scope.logout = () => {
  85. firebase.auth().signOut();
  86. $scope.loginEmail = "";
  87. $scope.loginPassword = "";
  88.  
  89. $scope.loginFormShow = true;
  90. $scope.logoutFormShow = false;
  91. };
  92.  
  93. //listener
  94. firebase.auth().onAuthStateChanged(firebaseUser => {
  95. if (firebaseUser) {
  96. //set ng-show
  97. $scope.loginFormShow = false;
  98. $scope.logoutFormShow = true;
  99. // console.log(firebaseUser);
  100. } else {
  101. //set ng-show
  102. $scope.loginFormShow = true;
  103. $scope.logoutFormShow = false;
  104. // console.log('not logged in');
  105. }
  106. });
  107.  
  108. }]);
  109.  
  110. app.run(["$rootScope", "$location", function($rootScope, $location) {
  111. $rootScope.$on("$routeChangeError", function(event, next, previous, error) {
  112.  
  113. if (error === "AUTH_REQUIRED") {
  114. $location.path("/");
  115. }
  116. });
  117. }]);
  118.  
  119. app.config(["$routeProvider", function($routeProvider) {
  120. $routeProvider
  121. .when("/home", {
  122. templateUrl: 'app/components/home/home.html',
  123. controller: 'HomeCtrl',
  124. resolve: {
  125. "currentAuth": ["Auth", function(Auth) {
  126. return Auth.$waitForAuth();
  127. }]
  128. }
  129. }).when("/address", {
  130. templateUrl: 'app/components/addresses/addressbook.html',
  131. controller: 'AddressCtrl',
  132. resolve: {
  133. return Auth.$requireAuth();
  134. }]
  135. }
  136. }).when("/login", {
  137. templateUrl: 'app/components/security/auth.html',
  138. });
  139. }]);
  140.  
  141. app.controller("HomeCtrl", ["currentAuth", "$scope", "$location", function(currentAuth, $scope, $location) {
  142.  
  143.  
  144. }]);
  145.  
  146. app.controller("AddressCtrl", ["currentAuth", function(currentAuth,$scope, $firebaseArray, $firebaseObject) {
  147.  
  148. }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement