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

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

问题描述

我已经看到很多关于此的问题,但让我感到困惑的是 firebase x nodejs 的 rel="nofollow noreferrer">文档 有一个函数 createUserWithEmailAndPassword().

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().

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

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

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

此外,在相同的 nodejs 文档下,firebase.auth() 说:

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

auth(app) 返回 firebase.auth.Auth

auth(app) returns firebase.auth.Auth

获取默认应用程序或给定应用程序的 Auth 对象.

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

用法:

firebase.auth() firebase.auth(app)

firebase.auth() firebase.auth(app)

所以我假设调用 firebase.auth() 将返回 firebase.auth.Auth 据称包含 createUserWithEmailAndPassword 函数.

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

注意

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

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

推荐答案

适用于 Node.js 的 Firebase SDK 可以在两种模式下工作(从 3.3 版开始):

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

  1. 作为服务器端 SDK,当您将其初始化为服务帐户时会发生这种情况

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

如果您使用服务帐户(3.2 及之前版本中唯一可用的选项)进行初始化,您的连接将自动通过管理员身份验证,您将只有 管理员身份验证功能可用:创建和验证自定义令牌.

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.

作为客户端 SDK,当您将其初始化为 API 密钥时会发生这种情况

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

如果您使用 API 密钥进行初始化(仅自版本 3.3 起可用),您将找到 客户端身份验证方法可用.

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

请参阅这篇关于 firebase-talk 的帖子完整的细节.

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

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