Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create users server-side Firebase Functions

I am trying to create a login GET request to the server side using the Firebase cloud functions.

Is it possible to auth using firebase functions? I tried npm i firebase inside the functions folder, but it fails to work.

Is there an option to create users using server-side code?

like image 754
ProgramKiddo Avatar asked Nov 13 '17 15:11

ProgramKiddo


People also ask

Can you add users to Firebase?

Add a memberSign in to Firebase. Click. , then select Permissions. On the Permissions page, click Add member.

Does Firebase support server side rendering?

Server-side rendering is a technique that allows your React application to serve pages on the server before sending them to the user's browser.

Can I use firebase Admin client side?

The Firebase Admin SDK should only be run in a privileged environment, like your server or Firebase Cloud Functions. It provides direct administrative access that is not secure on the client.

Can I create admin panel with Firebase?

Start by creating a new app on Retool, and give this app a name. We'll call it “Firebase Admin.” Next, create a Firebase resource by clicking "create a new resource" from the Resource field at the bottom panel. Select Firebase from the options to create a Firebase resource.


1 Answers

To create Firebase Authentication users from within Cloud Functions you use the Firebase Admin SDK for Node.js.

To install it, follow the instructions in the documentation. Mostly it's:

$ npm install firebase-admin --save

And then import it into your index.js using:

var admin = require("firebase-admin");

To create a user follow the instructions in this documentation:

admin.auth().createUser({
  email: "[email protected]",
  emailVerified: false,
  phoneNumber: "+11234567890",
  password: "secretPassword",
  displayName: "John Doe",
  photoURL: "http://www.example.com/12345678/photo.png",
  disabled: false
})
  .then(function(userRecord) {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log("Successfully created new user:", userRecord.uid);
  })
  .catch(function(error) {
    console.log("Error creating new user:", error);
  });
like image 114
Frank van Puffelen Avatar answered Oct 30 '22 01:10

Frank van Puffelen