swoosh
swoosh

Reputation: 657

unknown error creating user with firebase

I am receiving a CORS error from my browser while trying to implement a simple login authentication (email/password) with firebase.

I checked the security rules and it is set to

{
"rules": {
".read": true,
".write": true
 }
}

Here's a summary of my code from the example.

<script src="https://cdn.firebase.com/js/client/1.0.15/firebase.js"></script>
<script type='text/javascript' src='https://cdn.firebase.com/js/simple-login/1.5.0/firebase-simple-login.js'> </script>


var myRootRef = new Firebase('https://vivid-fire-myserver.firebaseio.com/');
var authClient = new FirebaseSimpleLogin(myRootRef, function(error, user) {
    if (error) {
        alert(error);
        return;
    }
    if (user) {
        alert('user already logged in');
    } else {
        alert('user logged out');
    }
});

$("#registerButton").on("click", function() {
    var email = $("#email").val();
    var password = $("#password").val();
    authClient.createUser(email, password, function(error,  user) {
        if (!error) {
            alert('registered successfully');
        } else {
            alert(error);
        }
    });
}); 

Upvotes: 0

Views: 1958

Answers (1)

swoosh
swoosh

Reputation: 657

It appears that the problem is a result of submitting my form, which causes the page to reload. As confirmed with Rob, "the reload is taking place before the HTTP OPTIONS request to the server checking the CORS configuration is able to complete.

A work around is to prevent the form from reloading upon submission. I did this by returning false in my html form and my jquery scripts.

<form class="m-t" role="form" onSubmit="return goLogin()">
..........

function goLogin() {
    $("#loginButton").click(function() {
    ......      
    )}; 

    return false;   
}

Upvotes: 1

Related Questions