Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 752
CENT1PEDE Avatar asked Jan 06 '23 10:01

CENT1PEDE


1 Answers

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("[email protected]", "firebase")
    .then(user => console.log(user))
    .catch(error => console.error(error));

See this post on firebase-talk for full details.

like image 117
Frank van Puffelen Avatar answered Jan 13 '23 09:01

Frank van Puffelen