简体   繁体   English

我尝试为 createUser 创建一个可调用的函数,但是我在运行它时遇到了一个错误,我不知道为什么

[英]I tried making a callable function for createUser but I am getting an error wen I run it and I can't figure out why

I am trying to make a user management page and I set up a callable function to run on my web app on firebase to create a new user.我正在尝试制作一个用户管理页面,并设置了一个可调用的函数,以在 firebase 上的 Web 应用程序上运行以创建一个新用户。 The html function is designed to update users or create new ones. html 函数旨在更新用户或创建新用户。 I am trying to test saving a new user.我正在尝试测试保存新用户。 As far as I can tell, all the variables match up, but it still receives an error.据我所知,所有变量都匹配,但它仍然收到错误。 The error isn't helpful, so I can't tell what's wrong.该错误没有帮助,所以我不知道出了什么问题。 Can someone help?有人可以帮忙吗?

userManagement.html用户管理.html

            function save(){
                if(document.getElementById("password").value === document.getElementById("p2").value){
                    if(document.getElementById("username").value === ""){
                        const createUser = firebase.functions().httpsCallable("createUser");
                        createUser({ email: document.getElementById("email").value, name:  document.getElementById("first").value + ' ' + document.getElementById("last").value, phone: document.getElementById("phone").value, password: document.getElementById("password").value})
                        .then((result) => {
                            // Read result of the Cloud Function.
                            console.log(result.data)
                        });
                    }
                    else{
                    const updateUser = firebase.functions().httpsCallable('updateUser');
                        // Passing params to data object in Cloud functinon
                        updateUser({ email: document.getElementById("email").value, name:  document.getElementById("first").value + ' ' + document.getElementById("last").value, phone: document.getElementById("phone").value, uid: document.getElementById("username").value})
                        .then((result) => {
                            // Read result of the Cloud Function.
                            console.log(result.data)
                        });
                        if(!(document.getElementById("password").value === "")){
                            const updatePassword = firebase.functions().httpsCallable('updatePassword');
                            // Passing params to data object in Cloud functinon
                            updatePassword({password: document.getElementById("password").value, uid: document.getElementById("username").value})
                            .then((result) => {
                                // Read result of the Cloud Function.
                                console.log(result.data)
                            });
                        }
                    }

                }
                else{
                    alert("password and confirm do not match")
                }
            }

index.js索引.js

  export const createUser = functions.https.onCall(async (data, context) => {
    const {email, name, phone, password} = data;
    await admin
    .auth()
    .createUser({
      email: email,
      displayName: name,
      phoneNumber: phone,
      password: password,
      emailVerified: true,
      disabled: false,
    }).then((result) => {
           // Read result of the Cloud Function.
           console.log(result.data)
    }).catch(console.error);
    return {data: `User updated`}
  });  

the imports for the pages are:页面的导入是:

        <script src="/__/firebase/8.7.1/firebase-app.js"></script>
        <script src="/__/firebase/8.7.1/firebase-analytics.js"></script>
        <script src="/__/firebase/8.7.1/firebase-auth.js"></script>
        <script src="/__/firebase/8.7.1/firebase-functions.js"></script>
        <script src="/__/firebase/8.7.1/firebase-firestore.js"></script>
        <script src="/__/firebase/init.js?useEmulator=true"></script>

and

import * as functions from "firebase-functions";

import * as admin from "firebase-admin";

Current errors:当前错误:

在此处输入图片说明

在此处输入图片说明

Someone helped me.有人帮助了我。 I forgot to initialize admin sdk.我忘了初始化 admin sdk。

暂无
暂无

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

相关问题 我不知道为什么我收到以下错误“错误:元素类型无效:” - I can't figure out why I am getting the following error "Error: Element type is invalid:" 我在JavaScript中变得未定义,无法弄清为什么 - I am getting undefined in JavaScript and can't figure it out why 在 API 的帮助下创建网页时,无法弄清楚为什么我的终端会出现此错误 - Can't figure out why I am getting this error in my terminal while creating a webpage with the help of API 我是 nodejs 的新手,我收到了参考错误:io is not defined ,我想不通 - I am new to nodejs and I'm getting reference error: io is not defined ,I can't figure it out 我不知道为什么我不断收到此错误 - I can not figure out why I keep getting this error 似乎无法弄清楚为什么使用jquery单击按钮后我没有收到警报 - Can't seem to figure out why am I not getting an alert after clicking a button using jquery 我不知道为什么我在这里得到“无法读取未定义的属性&#39;长度&#39;的错误”错误 - I can't figure out why I'm getting the “Cannot read property 'length' of undefined” error here 我的代码中不断出现“未捕获范围”错误,我不知道为什么 - I keep getting an 'uncaught range' error in my code and I can't figure out why 嗨,我刚开始反应原生,我无法弄清楚密钥提取器是如何工作的,因为我收到以下错误 - Hi, I just started react native and I can't figure out how key extractor works as I am getting the following error 无法弄清楚为什么我一直不确定 - Can't figure out why I keep getting undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM