javascript - Why can my code not access user that was just created? -
i'm using following code creating users:
firebase.auth().createuserwithemailandpassword($scope.data.mail, $scope.data.pwd) .catch(function(error) { }); var user; while (!user) { user = firebase.auth().currentuser; }
however don't know why time user variable gets null value: , loop never finished. i'm unable solve issue.
you can't use while
loop wait asynchronous result, because javascript runs on single thread.
the loop execute indefinitely, meaning javascript runtime never chance handle promise, if it's completed.
you need use then
clause of promise instead.
firebase.auth().createuserwithemailandpassword($scope.data.mail, $scope.data.pwd) .then(function() { var user = firebase.auth().currentuser; // carry on executing code here }) .catch(function(error) { });
Comments
Post a Comment