Firebase 3.3.x Nodejs – createUserWithEmailAndPassword不是一个函数

我已经看到了很多关于这个的问题,但令我困惑的是nodejs x nodejs的文档中有一个函数createUserWithEmailAndPassword()

每次我打印firebase.auth()它只有这些function:

 { createCustomToken: [Function], verifyIdToken: [Function], INTERNAL:{ delete: [Function], getToken: [Function], addAuthTokenListener: [Function], removeAuthTokenListener: [Function] } } 

另外,在同一个nodejs文档中,firebase.auth ()表示:

auth(app)返回firebase.auth.Auth

获取默认App或给定App的Auth对象。

用法:

firebase.auth()firebase.auth(app)

所以我认为调用firebase.auth()将返回firebase.auth.Auth ,它应该包含createUserWithEmailAndPassword函数。

注意

是的,我使用firebase.initializeApp()正确地初始化了firebase,它工作正常,我已经在做database事务JSYK。

适用于Node.js的Firebase SDK可以以两种模式工作(自3.3版本起):

  1. 作为一个服务器端的SDK,当你初始化它时,发生一个服务帐户

     firebase.initializeApp({ serviceAccount: "myproject-3d9889aaeddb.json", databaseURL: "https://myproject.firebaseio.com" }); 

    如果使用服务帐户进行初始化(在3.2版及之前的版本中唯一可用的选项),则您的连接将自动以pipe理员身份进行身份validation,并且只有pipe理员身份validationfunction可用:创build和validation自定义令牌。

  2. 作为一个客户端SDK,当你初始化它时会发生一个API密钥

     firebase.initializeApp({ apiKey: "myprojectsApiKey", databaseURL: "https://myproject.firebaseio.com" }); 

    如果您使用API​​密钥进行初始化(只能在版本3.3以上),您会发现可用的客户端身份validation方法 。

它只是在我自己的项目中validation了这一点:

 var firebase = require("firebase"); firebase.initializeApp({ apiKey: "AI...Sc", databaseURL: "https://stackoverflow.firebaseio.com" }); firebase.auth().createUserWithEmailAndPassword("nodeuser@firebaseui.com", "firebase") .then(user => console.log(user)) .catch(error => console.error(error)); 

有关完整的详细信息,请参阅firebase-talk上的这篇文章 。