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

问题描述 投票:1回答:1

我正在尝试使用云功能在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.js firebase firebase-authentication google-cloud-functions firebase-admin
1个回答
2
投票

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

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

createUserWithEmailAndPassword只存在in the client SDK

© www.soinside.com 2019 - 2024. All rights reserved.