ProgramKiddo
ProgramKiddo

Reputation: 333

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?

Upvotes: 8

Views: 7974

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598623

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);
  });

Upvotes: 15

Related Questions