我正在尝试使用Firebase在NodeJS中设置电子邮件和密码身份验证,但我不断收到此错误:TypeError: firebase.auth(...).createUserWithEmailAndPassword is not a function
代码:
var firebase = require('firebase-admin');
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: 'https://my-app-name.firebaseio.com'
});
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
console.log(errorMessage + errorCode);
if (errorMessage) {
res.status(500).send();
} else {
res.status(200).send();
}
});
答案 0 :(得分:2)
您显示的代码来自web client SDK,而不是Admin SDK。根据{{3}},来自Admin SDK的功能为:
firebase.auth().createUser({
email: email,
password: password
}).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);
});