Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.js:13642TypeError: Auth.$requireAuth is not a function
- at $routeProvider.when.when.resolve.currentAuth (app.js:129)
- at Object.invoke (angular.js:4708)
- at angular-route.js:631
- at Object.q [as forEach] (angular.js:336)
- at n (angular-route.js:628)
- at angular.js:16104
- at m.$eval (angular.js:17378)
- at m.$digest (angular.js:17191)
- at m.$apply (angular.js:17486)
- at HTMLHtmlElement.<anonymous> (angular.js:13391)(anonymous function)
- @angular.js:13642
- var app = angular.module("app", ["firebase", "ngRoute"]);
- app.factory("Auth", ["$firebaseAuth", "$rootScope", function($firebaseAuth) {
- var authRef = $firebaseAuth();
- return authRef;
- }]);
- app.controller("LoginCtrl", ["$scope", "Auth", "$location", function($scope, Auth, $location) {
- $scope.auth = Auth;
- $scope.user = $scope.auth.$getAuth();
- var isNewUser = true;
- //signup
- $scope.signUp = () => {
- isNewUser = true;
- //Get Email and Password
- // TODO: Check for real email
- const email = $scope.loginEmail;
- const pass = $scope.loginPassword;
- const auth = firebase.auth();
- // Sign in
- auth.createUserWithEmailAndPassword(email, pass);
- $scope.loginEmail = "";
- $scope.loginPassword = "";
- $scope.loginFormShow = false;
- $scope.logoutFormShow = true;
- $location.path('/home');
- };
- //set up user profile data
- firebase.auth().onAuthStateChanged(firebaseUser => {
- if (firebaseUser && isNewUser) {
- firebase.database().ref().child("userProfiles").child(firebaseUser.uid).set({
- name: firebaseUser.email,
- role: "user",
- tags: "tags"
- });
- }
- });
- //login
- $scope.login = () => {
- isNewUser = false;
- const email = $scope.loginEmail;
- const pass = $scope.loginPassword;
- const auth = firebase.auth();
- auth.signInWithEmailAndPassword(email, pass);
- //promise.catch(e => console.log(e.message));
- $scope.loginEmail = "";
- $scope.loginPassword = "";
- $scope.loginFormShow = false;
- $scope.logoutFormShow = true;
- $location.path('/home');
- };
- //logout
- $scope.logout = () => {
- firebase.auth().signOut();
- $scope.loginEmail = "";
- $scope.loginPassword = "";
- $scope.loginFormShow = true;
- $scope.logoutFormShow = false;
- };
- //listener
- firebase.auth().onAuthStateChanged(firebaseUser => {
- if (firebaseUser) {
- //set ng-show
- $scope.loginFormShow = false;
- $scope.logoutFormShow = true;
- // console.log(firebaseUser);
- } else {
- //set ng-show
- $scope.loginFormShow = true;
- $scope.logoutFormShow = false;
- // console.log('not logged in');
- }
- });
- }]);
- app.run(["$rootScope", "$location", function($rootScope, $location) {
- $rootScope.$on("$routeChangeError", function(event, next, previous, error) {
- if (error === "AUTH_REQUIRED") {
- $location.path("/");
- }
- });
- }]);
- app.config(["$routeProvider", function($routeProvider) {
- $routeProvider
- .when("/home", {
- templateUrl: 'app/components/home/home.html',
- controller: 'HomeCtrl',
- resolve: {
- "currentAuth": ["Auth", function(Auth) {
- return Auth.$waitForAuth();
- }]
- }
- }).when("/address", {
- templateUrl: 'app/components/addresses/addressbook.html',
- controller: 'AddressCtrl',
- resolve: {
- return Auth.$requireAuth();
- }]
- }
- }).when("/login", {
- templateUrl: 'app/components/security/auth.html',
- });
- }]);
- app.controller("HomeCtrl", ["currentAuth", "$scope", "$location", function(currentAuth, $scope, $location) {
- }]);
- app.controller("AddressCtrl", ["currentAuth", function(currentAuth,$scope, $firebaseArray, $firebaseObject) {
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement