2
votes

i tried sending the credentials and this error appears.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=*******. (Reason: CORS request did not succeed).

(function () {

  var config = {
    apiKey: "*******",
    authDomain: "*******",
    databaseURL: "*******",
    projectId: "*******",
    storageBucket: "*******",
    messagingSenderId: "*******"
  };
  firebase.initializeApp(config);

  const email = document.getElementById('email');
  const password = document.getElementById('password');
  const btnSignUp = document.getElementById('btnSignUp');

  btnSignUp.addEventListener('click', e => {
    const mail = email.value;
    const pass = password.value;

    firebase.auth().createUserWithEmailAndPassword(mail, pass).catch(function(error) {

      var errorCode = error.code;
      var errorMessage = error.message;

      if (errorCode == 'auth/weak-password') {
        alert('The password is too weak.');
      } else {
        alert(errorMessage);
      }
      console.log(error);

    });
  });
}());

How do I solve the CORS request blocked?

1
you have errors in your code pass is not allowed to be a variable nameSheshank S.
thank you i just change it to passo so does this help in the error i was getting?user7703138
Does the error still show up? @KaeSheshank S.
yes @SheshankS.user7703138
where are you testing this? on localhost? wherever you are, is that url on the allowed domains in firebase/Sheshank S.

1 Answers

0
votes

Your firebase imports are wrong, use this:

<!-- Firebase App is always required and must be first -->
<script src="https://www.gstatic.com/firebasejs/5.1.0/firebase-app.js"></script>

<!-- Add additional services that you want to use -->
<script src="https://www.gstatic.com/firebasejs/5.1.0/firebase-auth.js"></script>