Install the Firebase Node modules:
$ npm install firebase firebase-admin --save
2. Firebase Admin setup on Node.js REPL (see also: official guide)
Go to the Firebase console, click Project Settings (the little gear icon next to "Project Overview") and choose the Service Accounts tab. Node.js is selected by default, hit Generate new private key.
Following the instructions above the button (or in the official guide above) on the Node REPL:
const firebase_admin = require('firebase-admin');
const serviceAccount = require('./generated-service-account.json');
firebase_admin.initializeApp({
credential: firebase_admin.credential.cert(serviceAccount),
databaseURL: "https://your-app.firebaseio.com"
});
3. Firebase Client setup on Node.js REPL (see also: official guide)
const firebase_client = require('firebase');
var config = {
apiKey: "your-api-key",
authDomain: "your-app.firebaseapp.com",
databaseURL: "https://your-app.firebaseio.com",
projectId: "your-app",
storageBucket: "your-app.appspot.com",
messagingSenderId: "1234567"
};
firebase_client.initializeApp(config);
function add_user(displayName, email) {
firebase_admin.auth().createUser({
displayName: displayName,
email: email
}).then( function(_userRecord) {
firebase_client.auth().sendPasswordResetEmail(email);
});
}
I don't know if anyone still needs to know but basically using the firebase client SDK in the backend will lead to many issues and one of the main ones is the client going offline, so basically in the staging phase with localhost the server will tend to stop if you don't send requests for a long time because the firebase client will go offline, I am talking from experience because I used to have those issues but once I switched to firebase admin in the backend, everything became much easier and smoother.