本文介绍了使用REST API创建Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用REST API可以在Firebase中创建新的电子邮件/密码用户吗? 使用服务器创建用户
:
您可以在中使用官方JavaScript库,它会让你在服务器上创建用户(至少在JavaScript中)。
尝试:
然后像在浏览器根据。以下直接从文档:
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 (错误){
switch(error.code){
caseEMAIL_TAKEN:
console.log(新用户帐户无法创建,因为电子邮件已被占用。) ;
break;
caseINVALID_EMAIL:
console.log(指定的电子邮件不是有效的电子邮件地址);
break;
default:
console.log(创建用户的错误:,错误);
}
} else {
console.log(用uid成功创建用户帐户,userData.uid );
}
});
Is it possible to create new email/password users in Firebase using the REST API?
解决方案
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);
}
});
这篇关于使用REST API创建Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!