javascript - Uncaught Reference Error: Firebase is not defined - Stack Overflow

I have the following piece of code I'm trying to use to authenticate a newly registered user, alth

I have the following piece of code I'm trying to use to authenticate a newly registered user, although it fails to even initialize firebase, popping up this error:

Uncaught ReferenceError: firebase is not defined

Below is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd">
<html xmlns="" >
<head>
    <title>register</title>
    <script src=".12.2/jquery.min.js"></script>
    <script src='.4.2/firebase.js'></script>
</head>
<body>
    <script>
        var config = {
            databaseURL: '/'
        };
        firebase.initializeApp(config);

        var ref = new Firebase("/");

        function registerUser() {
            var email = document.getElementById("email").value;
            var password = document.getElementById("password").value;
            ref.auth().createNewUserWithEmailAndPassword(email, password);
        }
    </script>

    <div class="form">
        <div id="error"></div>
        <form onsubmit="registerUser();">
            <label>Email:</label>
            <input type="text" name="email" id="email"><br>
            <label>Password:</label>
            <input type="password" name="pwd" id="password"><br>
            <input type="submit" value="Sign Up"><br>
        </form>
    </div>
</body>
</html>

I have the following piece of code I'm trying to use to authenticate a newly registered user, although it fails to even initialize firebase, popping up this error:

Uncaught ReferenceError: firebase is not defined

Below is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml" >
<head>
    <title>register</title>
    <script src="https://ajax.googleapis./ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    <script src='https://cdn.firebase./js/client/2.4.2/firebase.js'></script>
</head>
<body>
    <script>
        var config = {
            databaseURL: 'https://apcs-4bfaa.firebaseio./'
        };
        firebase.initializeApp(config);

        var ref = new Firebase("https://apcs-4bfaa.firebaseio./");

        function registerUser() {
            var email = document.getElementById("email").value;
            var password = document.getElementById("password").value;
            ref.auth().createNewUserWithEmailAndPassword(email, password);
        }
    </script>

    <div class="form">
        <div id="error"></div>
        <form onsubmit="registerUser();">
            <label>Email:</label>
            <input type="text" name="email" id="email"><br>
            <label>Password:</label>
            <input type="password" name="pwd" id="password"><br>
            <input type="submit" value="Sign Up"><br>
        </form>
    </div>
</body>
</html>
Share Improve this question asked Jun 3, 2016 at 14:59 Henry ZhuHenry Zhu 2,62812 gold badges48 silver badges89 bronze badges 4
  • The Web Quickstart does not show any reference to a firebase object and all it seems to acplish is defining the same URL twice. Doesn't new Firebase() do it all? – Álvaro González Commented Jun 3, 2016 at 15:04
  • @ÁlvaroGonzález There is a new SDK that includes the firebase object. Check out firebase.google. – David East Commented Jun 3, 2016 at 15:08
  • You're using fairly old documentation. Be sure to use the latest (for any framework) to make sure everything is working correctly. @DavidEast has the right answer. – Alan Thomas Commented Jun 3, 2016 at 15:09
  • @AlanThomas It says ref.auth() is not a function. – Henry Zhu Commented Jun 6, 2016 at 15:05
Add a ment  | 

1 Answer 1

Reset to default 9

Your code is mixed up between the older 2.4.2 API and the the 3.0 SDK.

There are no more new Firebase() calls. You need to use the new SDK, currently 3.0.3, and then configure your app.

<script src="https://www.gstatic./firebasejs/3.0.3/firebase.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: '<your-api-key>',
    authDomain: '<your-auth-domain>',
    databaseURL: '<your-database-url>',
    storageBucket: '<your-storage-bucket>'
  };
  firebase.initializeApp(config);
</script>

After configuring you can then create references.

firebase.database().ref()

So in your case it would be:

<script>
    var config = {
        databaseURL: 'https://apcs-4bfaa.firebaseio./'
    };
    firebase.initializeApp(config);

    // new 3.0 SDK method!
    var ref = firebase.database().ref();

    function registerUser() {
        var email = document.getElementById("email").value;
        var password = document.getElementById("password").value;
        firebase.auth().createNewUserWithEmailAndPassword(email, password);
    }
</script>

Check out the docs for more info.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744291201a4567040.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信