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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -