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);
});
}
Using firebase client SDK in the backend is not a good practice.