firebase TypeError:admin.fireStore不是函数

zwghvu4y  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(97)

我试图做一个简单的函数,在创建帐户时将用户数据添加到我的firestore中。据我所知,我一切都是正确的,但它显然不起作用。有一件事我不确定是否奇怪,那就是我有两个package.json文件,但我会提供它们。
这是我的index.js

import admin from "firebase-admin";
import express from "express";
import { onRequest } from "firebase-functions/v2/https";

const router = express.Router();

const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(router);

const addUserData = onRequest(async (req, res) => {
  console.log(req.body);

  const addData = await admin.fireStore().collection("users").doc(req.uid).set({
    firstName: req.firstName,
    lastname: req.lastName,
    dob: req.dob,
    email: req.email,
  });
  res.send(addData.responseCode);
});

router.put("/addUserData", addUserData);

const api = onRequest(app);

export { api as app };

字符串
我的package.json(在functions文件夹中)

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint --ext .js --ignore-path .gitignore .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "16"
  },
  "type": "module",
  "main": "index.js",
  "devDependencies": {
    "eslint": "^8.15.0",
    "eslint-config-google": "^0.14.0",
    "firebase-functions-test": "^3.1.0",
    "firebase-functions": "^4.4.1",
    "firebase-admin": "^11.10.1"
  },
  "private": true
}


和我的package.json在我的函数文件夹之外:

{
  "scripts": {
    "lint": "eslint --ext .js --ignore-path .gitignore .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "dependencies": {
    "express": "^4.18.2",
    "firebase-admin": "^11.10.1",
    "firebase-functions": "^4.4.1",
    "googleapis": "^122.0.0"
  }
}


这是我第一次尝试使用firebase并自己建立一个项目,所以我可能错过了一些明显的东西,但我无法从所有的帖子中找到任何东西。

wh6knrhe

wh6knrhe1#

也许这个会有帮助
admin.fireStore()更改为admin.firestore()

const addData = await admin.firestore().collection("users").doc(req.uid).set({
    firstName: req.firstName,
    lastname: req.lastName,
    dob: req.dob,
    email: req.email,
  });

字符串
您应该检查firebase authentication triggers

相关问题