The Green Foxx The Green Foxx - 11 months ago 150
Node.js Question

Firebase 3.3.x Nodejs - createUserWithEmailAndPassword is not a function

I've seen a lot of questions about this, but what confuses me is on the documentation of

firebase
x
nodejs
there is a function
createUserWithEmailAndPassword()
.

Everytime I print
firebase.auth()
it only has these functions :

{
createCustomToken: [Function],
verifyIdToken: [Function],
INTERNAL:{
delete: [Function],
getToken: [Function],
addAuthTokenListener: [Function],
removeAuthTokenListener: [Function]
}
}


Also, under the same nodejs documentation, the firebase.auth() says :


auth(app) returns firebase.auth.Auth

Gets the Auth object for the default App or a given App.

Usage:

firebase.auth() firebase.auth(app)


So I assumed that calling
firebase.auth()
will return firebase.auth.Auth which supposedly contains the createUserWithEmailAndPassword function.

NOTE

Yes, I properly initialized firebase using
firebase.initializeApp()
and it is working properly, Im already doing
database
transactions JSYK.

Answer Source

The Firebase SDK for Node.js can work in two modes (since version 3.3):

  1. as a server-side SDK, which happens when you initialize it work a service account

    firebase.initializeApp({
      serviceAccount: "myproject-3d9889aaeddb.json",
      databaseURL: "https://myproject.firebaseio.com"
    });
    

    If you initialize with a service account (the only option available in version 3.2 and before), your connection will automatically be authenticated as an admin and you will only have admin auth functionality available: creating and verifying custom tokens.

  2. as a client-side SDK, which happens when you initialize it work an API key

    firebase.initializeApp({
      apiKey: "myprojectsApiKey",
      databaseURL: "https://myproject.firebaseio.com"
    });
    

    If you initialize with an API key (only possible since version 3.3), you will find the client-side authentication methods available.

It just verified this in a project of my own:

var firebase = require("firebase");

firebase.initializeApp({
  apiKey: "AI...Sc",
  databaseURL: "https://stackoverflow.firebaseio.com"
});

firebase.auth().createUserWithEmailAndPassword("nodeuser@firebaseui.com", "firebase")
    .then(user => console.log(user))
    .catch(error => console.error(error));

See this post on firebase-talk for full details.