我们如何在node.js中使用Firebase Auth创建用户?
我正在尝试使用nodejs中的Firebase身份验证创建用户帐户。它不起作用,我不知道为什么。这是nodejs生成的代码和错误:
var config = {.......}; // i can't share the config
var app = firebase.initializeApp(config);
var db = app.database();
var auth = app.auth();
auth.createUserWithUsernameAndPassword("[email protected]", "@NewPassWord").then(
function(user){ console.log(user);},
function(error){ console.error(error);}
);
NodeJS生成错误:
TypeError: Object [object Object] has no method 'createUserWithUsernameAndPassword'
at Object.<anonymous> (/home/antonio/Projects/firebase/app.js:20:6)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
回答如下:
截至2017年5月,这是我们成功使用的。
// Create the authenticated user
admin.auth().createUser({
email: email,
password: password,
displayName: `${firstName} ${lastName}`,
})