I don't understand the difference between Firebase SDK and Firebase SDK for cloud functions. I mean, when you run in command line "firebase init" in node.js, node modules will be downloaded to initialize a new project. But if i run "npm install firebase" different node modules appears, with similar names and different contents. So the question is: which SDK should I use to run functions and authentication in the same code? (I got a lot of require error from importing similar things and I don't know how to solve the problem).

Here is the code:

const functions = require('firebase-functions');
var firebase = require('firebase');


firebase.auth().onAuthStateChanged(function(user) {
   if (user) {

     // User is signed in.
   } else {
    // No user is signed in.

exports.delete = functions.https.onRequest((request, response) => {



The error says firebase.auth() is not a function, maybe for bad import and I don't know which package I need to import

1 Answers

Doug Stevenson On

npm install firebase installs modules to be used in client code that accesses Firebase products such as Firebase Authentication, Realtime Database, Firestore, and Cloud Storage.

npm install firebase-functions install modules to be used when writing backend code to deploy to Cloud Functions.

You're trying to use the Firebase Authentication client side library to listen to auth state changes in Cloud Functions. This isn't going to work, since that auth library only works on web clients.