Firebase 3.3.x Nodejs - createUserWithEmailAndPassword不是一个函数 [英] Firebase 3.3.x Nodejs - createUserWithEmailAndPassword is not a function

查看:153
本文介绍了Firebase 3.3.x Nodejs - createUserWithEmailAndPassword不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到很多关于这个的问题,但是让我感到困惑的是 firebase x nodejs 的文档函数 createUserWithEmailAndPassword()
$ b

每次打印 firebase.auth()时,都只有这些函数:

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

另外,在同一个nodejs文档中,说:

lockquote
firebase.auth.Auth



获取默认应用程序或给定应用程序的Auth对象。 $ b

用法:
$ b firebase.auth()firebase.auth(app)

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


$ b

注意



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

(从版本3.3开始):


  1. 作为服务器端SDK,帐户

      firebase.initializeApp({
    serviceAccount:myproject-3d9889aaeddb.json,
    databaseURL:https://myproject.firebaseio.com
    });如果您使用服务帐户进行初始化(3.2版及以前的唯一选项),则您的连接会自动以管理员身份进行身份验证,您只能获得管理员身份验证功能:正在创建并验证自定义令牌。
  2. 作为客户端SDK,当您初始化它时会发生一个API密钥

      firebase.initializeApp({
    apiKey:myprojectsApiKey,
    databaseURL:https://myproject.firebaseio .com
    });如果您使用API​​密钥进行初始化(仅在版本3.3以上才有可能),您会发现 $ / code>

    href =https://firebase.google.com/docs/reference/node/firebase.auth.Auth#createUserWithEmailAndPassword =noreferrer>客户端身份验证方法


这只是在我自己的项目中验证过的:

  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上的这篇文章详细介绍。


I've seen a lot of questions about this, but what confuses me is on the documentation of firebase x nodejs there is a function createUserWithEmailAndPassword().

Everytime I print firebase.auth() it only has these functions :

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

Also, under the same nodejs documentation, the firebase.auth() says :

auth(app) returns firebase.auth.Auth

Gets the Auth object for the default App or a given App.

Usage:

firebase.auth() firebase.auth(app)

So I assumed that calling firebase.auth() will return firebase.auth.Auth which supposedly contains the createUserWithEmailAndPassword function.

NOTE

Yes, I properly initialized firebase using firebase.initializeApp() and it is working properly, Im already doing database transactions JSYK.

解决方案

The Firebase SDK for Node.js can work in two modes (since version 3.3):

  1. as a server-side SDK, which happens when you initialize it work a service account

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

    If you initialize with a service account (the only option available in version 3.2 and before), your connection will automatically be authenticated as an admin and you will only have admin auth functionality available: creating and verifying custom tokens.

  2. as a client-side SDK, which happens when you initialize it work an API key

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

    If you initialize with an API key (only possible since version 3.3), you will find the client-side authentication methods available.

It just verified this in a project of my own:

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));

See this post on firebase-talk for full details.

这篇关于Firebase 3.3.x Nodejs - createUserWithEmailAndPassword不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆