Firebase 功能模拟器获取参与者用户信息

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

我需要在创建Firestore对象时构造特定的链接文档,并且我需要知道谁创建了特定文档。根据文档,我应该能够使用包含身份验证信息的 onDocumentCreatedWithAuthContext 。

我尚未将其部署到 Firebase,仅在本地使用最新的 Firebase 模拟器。这是我的功能,我没有获得正确的身份验证信息。

"use strict";

// The Cloud Functions for Firebase SDK to create Cloud Functions and triggers.
const {logger} = require("firebase-functions");
const {onRequest} = require("firebase-functions/v2/https");
const {onDocumentCreatedWithAuthContext} = require("firebase-functions/v2/firestore");

// The Firebase Admin SDK to access Firestore.
const {initializeApp} = require("firebase-admin/app");
const {getFirestore} = require("firebase-admin/firestore");

initializeApp();

exports.createFamilyLinks = onDocumentCreatedWithAuthContext("/thecollection/{documentId}", (event) => {
  const { authType, authId } = event;
  logger.log(authType, authId);
});

创建文档时,日志输出:

{"severity":"INFO","message":"unknown [email protected]"}

这可能是 Firebase 模拟器的限制,还是我应该期望它不起作用?参考文档:https://firebase.google.com/docs/functions/firestore-events?gen=2nd#auth-context

node.js google-cloud-firestore firebase-authentication google-cloud-functions firebase-tools
1个回答
0
投票

我也没有成功地仅使用模拟器使其工作。我还收到 authTypeknown 和与 authId 相同的电子邮件,尽管我期望 uid。 所以,不幸的是我无法帮助你,我也在寻找这个问题的答案,但是我可以告诉你这在生产中对我有用,所以回答你的问题:

这可能是 Firebase 模拟器的限制,还是我应该 预计这不起作用?

它在生产中为我工作,但我在本地得到与你相同的结果。

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