vendredi 26 juin 2020

Getting the "Cannot access 'firebase' before initialization" error when using Firebase with JavaScript

This is the HTML Code. I get the "Cannot access 'firebase' before initialization" error when using Firebase with JavaScript. I have tried to move the tags around but does not seem to be working.

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <title>Login</title>
        <meta charset="utf-8">
    </head>
    <body>
        <script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-app.js"></script>
        <script src="https://www.gstatic.com/firebasejs/7.15.4/firebase-auth.js"></script>
        <script src="https://www.gstatic.com/firebasejs/7.15.4/firebase-firestore.js"></script>
        <script src="form.js"></script>
        <section>
            <input id="email" name="email" placeholder="email">
            <input id="password" name="password" placeholder="password">

            <button onclick=signUp() id="signUp" type="button">Sign Up</button>
        </section>
    </body>
</html>

This is the JS code without the parameters.

var firebaseConfig = {
apiKey: 
authDomain: 
databaseURL:
projectId: 
storageBucket: 
messagingSenderId: 
appId: 
measurementId:
};
  // Initialize Firebase
    firebase.initializeApp(firebaseConfig);
    firebase.analytics();

const firebase = firebase.auth();

function singUp() {
    var email = document.getElementById("email");
    var password = document.getElementById("password");

    const promise = auth.createUserWithEmailAndPassword(email.value, password.value);
    promise.catch(e => alert(e.message));

    alert("Signed Up");
}

I can't seem to be initializing firebase. Do you know what is wrong?




Aucun commentaire:

Enregistrer un commentaire