Is it possible to create new email/password users in Firebase using the REST API?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I'm just getting started with Firebase myself. However, couldn't you just use the JavaScrip API to create a new user (https://www.firebase.com/docs/web/api/firebase/createuser.html)? If you fire this each time a user logs into your application, you will migrate your users over and also have the advantage that users won't need to change their password.
回答2:
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);
}
});