简体   繁体   English

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

[英]Firebase - TypeError: admin.auth(…).createUserWithEmailAndPassword is not a function

I am trying to create a user in firebase database using cloud functions.我正在尝试使用云函数在 firebase 数据库中创建一个用户。 This is my code :这是我的代码:

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

    }

});

This is my package.json:这是我的 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
}

It works when I use admin.createUser() only but then I cannot use user.sendEmailVerification() because for some reasons its only available if the user is created using admin.createUserWithEmailAndPassword() .当我只使用admin.createUser()但我不能使用user.sendEmailVerification()它有效,因为由于某些原因它只有在用户是使用admin.createUserWithEmailAndPassword()创建时才可用。

This is what I get in firebase console :这是我在 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)

What do I do?我该怎么办? Here,这里,

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

I am new to firebase and cloud functions so apologies.我是 firebase 和 cloud 功能的新手,所以很抱歉。

The message is telling you everything you need to know.该消息告诉您需要知道的一切。 There is no method of that name in the node admin SDK.节点管理 SDK 中没有该名称的方法。

You can see a list of all the methods on admin.auth() in the API docs .您可以在 API 文档 中查看admin.auth()上所有方法的列表。

createUserWithEmailAndPassword only exists in the client SDK . createUserWithEmailAndPassword 只存在于客户端 SDK 中

you just have to use auth().createUser instead of createUserWithEmailAndPassword你只需要使用auth().createUser而不是createUserWithEmailAndPassword

admin.auth().createUser({
 email: 'user@example.com',
 emailVerified: false,
 phoneNumber: '+11234567890',
 password: 'secretPassword',
 displayName: 'John Doe',
 photoURL: 'http://www.example.com/12345678/photo.png',
 disabled: false
})
.then(function(userRecord) {
  // See the UserRecord reference doc for the contents of userRecord.
  console.log('Successfully created new user:', userRecord.uid);
})
 .catch(function(error) {
  console.log('Error creating new user:', error);
 });

check this out: https://firebase.google.com/docs/auth/admin/manage-users#create_a_user看看这个: https : //firebase.google.com/docs/auth/admin/manage-users#create_a_user

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase功能错误<admin.auth is not a function at ..> - Firebase function error <admin.auth is not a function at ..> 管理员firebase错误:“ admin.auth(...)。generatePasswordResetLink不是函数” - Error with admin firebase: “admin.auth(…).generatePasswordResetLink is not a function” admin.auth(...)。createSessionCookie不是函数 - admin.auth(…).createSessionCookie is not a function Firebase admin.auth()。getUser(uid)挂起(NodeJS) - Firebase admin.auth().getUser(uid) hangs (NodeJS) firebase.auth().createUserWithEmailAndPassword Undefined 不是函数 - firebase.auth().createUserWithEmailAndPassword Undefined is not a function Firebase管理员:admin.auth()。delete(uid)在AVA test.after()中无法解析 - Firebase Admin: admin.auth().delete(uid) not resolving in AVA test.after() admin.auth().verifyIdToken(idToken) 错误:在 8.0.0 之后无法使用 firebase-admin 加载默认凭据 - admin.auth().verifyIdToken(idToken) Error: Could not load the default credentials whith firebase-admin after to 8.0.0 firebase是否对每个admin.auth()。verifyIdToken(idToken)发出网络请求? - Does firebase make a network request for every admin.auth().verifyIdToken(idToken)? 在 app.js 中导入 firebase 后,我进行了初始化,但在控制器 firebase.auth.createUserWithEmailAndPassword 中不是函数 - After importing firebase in app.js I initialized but in controller firebase.auth.createUserWithEmailAndPassword is not a function Firebase 3.3.x Nodejs - createUserWithEmailAndPassword不是函数 - Firebase 3.3.x Nodejs - createUserWithEmailAndPassword is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM