Search code examples
javascriptfirebasefirebase-authenticationreferenceerror

how do i fix this Uncaught ReferenceError?


I am pretty new to java script. I am following along on a tutorial on how to get firebase to authorize on my page. I just have a simple button that SHOULD pull up the google login.

The error is "(index):96 Uncaught ReferenceError: googlelogin is not defined at HTMLButtonElement.onclick ((index):96) onclick @ (index):96"

Im pretty certain this is an easy fix. Like I said, fairly new. Thanks in advance!

In the HTML

<body>
    <h1>testing</h1>
    <button onclick="googlelogin()">login</button> 

    <script>
        src = "app.js"
    </script>
</body>

In app.js

document.addEventListener("DOMcontentloaded", event => {

        const app = firebase.app();
        console.log(app)

    )
}

function googlelogin() {
    const provider = new firebase.auth.GoogleAuthProvider();

    firebase.auth().signupwithpopup(provider)

    .then(result => {
            const user = result.user
            document.write('Hello $(user.displayname');
            console.log(user)
        })
        .catch(console.log)

Solution

  • Your current code just sets a global variable called src to the value of app.js. I think you want to actually load app.js

    <body>
        <h1>testing</h1>
        <button onclick="googlelogin()">login</button> 
    
        <script src="app.js"></script>
    </body>