Reputation: 381
I am using AngularJS with firebase for firebaseSimpleLogin. It worked a while ago and suddenly it doesn't work. Login part works fine but new users cannot sign up.
var userAuthRef = new Firebase(URL+"/userAuth");
$scope.loginObj = $firebaseSimpleLogin(userAuthRef);
$scope.userSignup = function(){
$('.signup.small.modal').modal('hide');
if ($scope.Password!="" && angular.equals($scope.PasswordFirst, $scope.PasswordConfirm)){
console.log($scope.Email + $scope.PasswordConfirm); ////the first log
$scope.loginObj.$createUser($scope.Email,$scope.PasswordConfirm)
.then(function(auth) {
console.log("reached here"); ////the second log
if (auth === null) {
console.log("Error creating user:", error);
} else {
console.log("User created successfully");
$scope.loginObj.$login("password", {
email: $scope.Email,
password: $scope.PasswordConfirm
}).then(function(user) {
console.log("Logged in as: ", user.uid);
userRef = $firebase(new Firebase(someURL+user.uid));
userRef.$set({username: $scope.Username, time: Date(), reported: 0});
$scope.user = userRef.$asObject();
}, function(error) {
console.error("Login failed: ", error);
});
}
}), function(error){
console.error("signup failed: ", error);
////Sign up failure log
};
}
else{
console.log("condition does not satisfy");
}
};
I am pretty sure the function userSignup() is called since the first console.log did print out something. Then I don't even know if $createUser is performed since console doesn't give anything anymore.
These are the rules on the Firebase forge:
{
"rules": {
".read": true,
"$user": {
".write": true
}
}
}
Is the usage of $createUser wrong??
Upvotes: 0
Views: 379
Reputation: 56
I think this problem occurs because FirebaseSimpleLogin is now a part of the standard firebase library. See here, it is deprecated: https://www.firebase.com/docs/web/api/firebasesimplelogin/
From now on use the api as described here: https://www.firebase.com/docs/web/api/firebase/createUser.html
If you still want an object with data about the authentication, use .getAuth(): https://www.firebase.com/docs/web/api/firebase/getAuth.html
Try the code below:
var userAuthRef = new Firebase(URL);
$scope.userSignup = function() {
if ($scope.Password != "" && angular.equals($scope.PasswordFirst, $scope.PasswordConfirm)) {
$('.signup.small.modal').modal('hide');
console.log($scope.Email + $scope.PasswordConfirm); ////the first log
firebaseRef.createUser({
email: $scope.Email,
password: $scope.PasswordConfirm
}, function(err) {
console.log("reached here"); ////the second log
if (err) {
switch (err.code) {
case 'EMAIL_TAKEN':
console.log("Error creating user, email taken:", error);
case 'INVALID_EMAIL':
console.log("Error creating user, invalid email:", error);
case
default:
console.log("Error creating user:", error);
}
} else {
// User account created successfully!
console.log("User created successfully");
dataRef.authWithPassword({
"email": $scope.Email,
"password": $scope.PasswordConfirm
}, function(error, authData) {
if (error) {
console.log('Login Failed!', error);
} else {
console.log('Authenticated successfully with payload:', authData);
console.log("Logged in as: ", authData.uid);
var userRef = $firebase(new Firebase(someURL + authData.uid));
userRef.$set({
username: $scope.Username,
time: Date(),
reported: 0
});
$scope.user = userRef.$asObject();
}
});
}
});
}
}
Upvotes: 1