1

Here's my code. I get this error semi-consistently when logging in, but if the login button is clicked twice it happens every time.

app.controller('login', ['$scope', '$state', '$rootScope', '$localStorage', '$location', 'userData', '$firebaseObject', 'firebase', '$timeout', function($scope, $state, $rootScope, $localStorage, $location, userData, $firebaseObject, firebase, $timeout) {
    var _ = firebase.database().ref()
    $scope.signin = function(user) {
        firebase.auth().signInWithEmailAndPassword(user.email, user.password).then(function(user) { 
            $localStorage.currentUser = user
            $localStorage.me = $firebaseObject(_.child('user/' + $localStorage.currentUser.uid))            
        }).catch(function(error) {
            console.log(error)
        });
    }
}]); 

I don't see what could be triggering the error, and it must be on this page because as of yet, I'm not redirecting to anywhere else.

enter image description here

I thought this may have been my error: Error: Maximum call stack size exceeded on Angualr Ui Router State Change but if I understand it right, this is due to a redirection loop, I'm not doing any redirecting, just opening a Firebase Auth session correct?

UPDATE: After removing both $localStorage lines, the error does not occur, issue with my implementation or $localStorage?

Community
  • 1
  • 1

1 Answers1

1

Alright so I found a solution to this problem, it appears the issue occurs when writing the entire Firebase Auth user object to the $localStorage object. Not sure what limitations $localStorage has but there was an issue somewhere. My solution was to parse out only the needed data and save that to the $localStorage:

    $scope.signin = function(user) {
        firebase.auth().signInWithEmailAndPassword(user.email, user.password).then(function(user) { 
            serializeUser(user)
        }).catch(function(error) {
            swal('Oops', 'There was an error: ' + error.message, 'error')
        });
    }

    var serializeUser = function(user) {
        var object = {
            email: user.email,
            uid: user.uid
        }
        $localStorage.currentUser = object
    }