node.js - Firebase - TypeError : admin. auth(...).createUserWithEmailAndPassword 不是函数

标签 node.js firebase firebase-authentication google-cloud-functions firebase-admin

我正在尝试使用云函数在 firebase 数据库中创建一个用户。这是我的代码:

exports.AddUser = functions.https.onRequest(function(req, res){

    if(req.method == 'GET'){
        email = req.query.email;
        password = req.query.password;
        name = req.query.name;

        admin.auth().createUserWithEmailAndPassword(email, password).then(function(user){
            user.sendEmailVerification().then(function(){
                res.send("verification email sent.");
            }).catch(function(){
                res.end(user)
            })
        })
        .catch(function(error) {
            // Handle Errors here.
            var errorCode = error.code;
            var errorMessage = error.message;
            console.log(errorMessage);
            res.send(errorMessage);
        });

    }else{
        email = req.body.email;
        password = req.body.password;
        name = req.body.name;

        admin.auth().createUserWithEmailAndPassword(email, password).then(function(user){
            user.sendEmailVerification().then(function(){
                res.send("verification email sent.");
            }).catch(function(error){
                res.end(user)
            });
        })
        .catch(function(error) {
            // Handle Errors here.
            var errorCode = error.code;
            var errorMessage = error.message;
            console.log(errorMessage);
            res.send(errorMessage);
        });

    }

});

这是我的 package.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "firebase-admin": "~5.12.0",
    "firebase-functions": "^1.0.1"
  },
  "private": true
}

它只在我使用 admin.createUser() 时有效,但后来我不能使用 user.sendEmailVerification() 因为出于某些原因它只有在创建用户时才可用使用 admin.createUserWithEmailAndPassword()

这是我在 firebase 控制台中得到的:

TypeError: admin.auth(...).createUserWithEmailAndPassword is not a function
    at /user_code/index.js:26:26
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:37:41)
    at /var/tmp/worker/worker.js:684:7
    at /var/tmp/worker/worker.js:668:9
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)

我该怎么办?在这里,

const functions = require('firebase-functions');
const admin = require('firebase-admin');

我是 Firebase 和云函数的新手,所以很抱歉。

最佳答案

该消息告诉您您需要知道的一切。 Node 管理 SDK 中没有该名称的方法。

您可以在 admin.auth() 上看到所有方法的列表 in the API docs .

createUserWithEmailAndPassword 只存在in the client SDK .

关于node.js - Firebase - TypeError : admin. auth(...).createUserWithEmailAndPassword 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50883762/

相关文章:

node.js - 快速中间件缓存

node.js - NodeJS、TypeScript 和 typescript 集合

swift - Firebase : Read-only & non-realtime mode activated, 如何在控制台上添加子节点

firebase - 如何向 Firebase 添加额外的用户信息

node.js - backbone.js 中的嵌套模板渲染

javascript - 按键值递归排序 JavaScript 对象

c++ - 使用 REST (Firebase) 时的离线功能

security - 如何以编程方式修改 Firebase 中的安全规则?

react-native - RNGoogleSignin 试图覆盖 RNGoogleSigninModule 错误

ios - 检查 Firebase 登录状态