且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用REST API创建Firebase

更新时间:2022-10-14 22:34:41

Creating users from the server:

You can use the official JavaScript library in Node.js, which will let you create users on the server (in JavaScript at least).

Try:

➤ npm install firebase

And then use it as you would in the browser according to the official documentation. The following straight from the docs:

var Firebase = require('firebase');

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.createUser({
  email: "bobtony@firebase.com",
  password: "correcthorsebatterystaple"
}, function(error, userData) {
  if (error) {
    switch (error.code) {
      case "EMAIL_TAKEN":
        console.log("The new user account cannot be created because the email is already in use.");
        break;
      case "INVALID_EMAIL":
        console.log("The specified email is not a valid email.");
        break;
      default:
        console.log("Error creating user:", error);
    }
  } else {
    console.log("Successfully created user account with uid:", userData.uid);
  }
});