Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase.auth().createUserWithEmailAndPassword Undefined is not a function

I am following the firebase documentation on user management

var firebase = require('firebase');

// Initialize Firebase
firebase.initializeApp({
    serviceAccount: "./<mysecreturledittedout>.json",
    databaseURL: "https://<mydatabaseurljusttobesafe>.firebaseio.com"
});

router.get('/create', function(req, res){
    var email = req.email;
    var password = req.password;
    firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(err){ // LINE 27 CRASH
        var errorCode = err.code;
        var errorMessage = error.message;
        console.log("ERROR");
        console.log(errorCode, errorMessage);
    });
});

I get the following error

undefined is not a function

TypeError: undefined is not a function
    at d:\Users\Kitty\Code\Practice2\routes\index.js:27:21

From doing a little bit of research, I think undefined is not a function is basically a javascript version of a null pointer exception (could be wrong)

I have configured my service account and project on firebase. I am running this on localhost. Thanks. I am looking primarily for debugging tips, as I'm not sure how to test what isn't working.

like image 897
Script Kitty Avatar asked May 28 '16 22:05

Script Kitty


1 Answers

If you haven't fixed the problem yet, I found out why it's giving such an error and that's because it really isn't a function.

You're using the Web reference as your guide when you need to be using the Server reference: https://firebase.google.com/docs/reference/node/firebase.auth.Auth.

As you can see, firebase.auth.Auth is a lot different on the Node.js API when compared to the Web API as there's not a lot in there. Now you have to deal with tokens, which I haven't looked deep into, if using the Server API. On the other hand, you can just use the Web API, which does things you intended to do.

like image 63
Sammy Franklin Avatar answered Oct 12 '22 22:10

Sammy Franklin