简体   繁体   English

响应 Firebase Authentication 事件触发 Cloud Run

[英]Trigger Cloud Run in response to Firebase Authentication event

According to the Firebase Functions Authentication Triggers documentation : " You can trigger Cloud Functions in response to the creation and deletion of Firebase user accounts. "根据Firebase Functions Authentication Triggers 文档:“您可以触发 Cloud Functions 以响应 Firebase 用户帐户的创建和删除。

Is it possible to trigger a Cloud Run service in the same way?是否可以以相同的方式触发 Cloud Run 服务? I've also tried digging through the docs to see if Firebase Authentication will publish on a pub/sub topic, hoping I could trigger the Cloud Run service that way, but all I can find is documentation for Cloud Function triggers.我还尝试通过文档挖掘 Firebase 身份验证是否会在发布/订阅主题上发布,希望我可以通过这种方式触发 Cloud Run 服务,但我能找到的只是 Cloud Function 触发器的文档。

I've also tried digging through the docs to see if Firebase Authentication will publish on a pub/sub topic`我还尝试浏览文档以查看 Firebase 身份验证是否会在发布/订阅主题上发布`

Yes it is totally possible for a Cloud Function to create and send messages to a specific topic.是的,云 Function 完全有可能创建消息并将消息发送到特定主题。 Let's see below an example for a user creation:让我们看看下面的用户创建示例:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// ...
const { PubSub } = require('@google-cloud/pubsub');
// ...

exports.publishToTopic = functions.auth.user().onCreate(async (user) => {
  // A Cloud Function triggered when a user is created
  // The below code should preferably be in a try/catch block
  
  const userId = user.uid;
  const email = user.email;

  const pubSubClient = new PubSub();

  const topic = 'firebase-user-creation';  // For example
  const pubSubPayload = { userId, email };
  const dataBuffer = Buffer.from(JSON.stringify(pubSubPayload));
  return pubSubClient.topic(topic).publish(dataBuffer);
  
});

For now, you can't trigger a Cloud Run on a Firebase event (and also on firestore event).目前,您无法在 Firebase 事件(以及 firestore 事件)上触发 Cloud Run。 Only Cloud Functions can be triggered.只能触发 Cloud Functions。 So, you can这样你就可以

  • Create a Cloud Functions that proxy the event (or as proposed by renaud, to transform this event in PubSub message that trigger your Cloud Run with a push subscription)创建代理事件的 Cloud Functions(或按照 renaud 的建议,在 PubSub 消息中转换此事件,通过推送订阅触发您的 Cloud Run)
  • Create a Cloud Functions that perform the business logic that you wanted to do in Cloud Run创建执行您希望在 Cloud Run 中执行的业务逻辑的 Cloud Functions
  • Wait for an update in Eventarc to take into account the firebase/firestore events (I haven't input on that could be in 2021 or not...)等待 Eventarc 中的更新以考虑到 firebase/firestore 事件(我没有输入可能是在 2021 年还是不是......)

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

相关问题 Firebase身份验证触发器的云功能 - Cloud Functions for Firebase Authentication trigger Firebase 云函数身份验证触发时间 - Firebase Cloud Function Authentication Trigger timing 如何在读取事件时触发Firebase云功能 - how to trigger firebase cloud function on read event 我可以在 Cloud Functions Http 触发器中创建 Firebase 身份验证用户吗? - Can I create a user on Firebase Authentication in Cloud Functions Http Trigger? 从身份验证事件触发的云功能是否可以保证运行? - Are cloud functions that trigger from authentication events guaranteed to run? Slack API事件订阅可触发Firebase云功能 - Slack API Event Subscription to trigger Firebase Cloud Functions firebase 云功能 v2 - 未部署自定义事件触发器 - firebase cloud functions v2 - custom event trigger not deployed Firebase 云函数数据库触发器有时无法正确运行 - Firebase cloud functions database trigger is not run correctly sometime firebase 云函数身份验证:onCreate 事件不包含 displayName - firebase cloud function authentication: onCreate event doesn't contain displayName Firebase函数已部署,但没有生成日志,也没有响应onCreate()事件触发 - Firebase function deploys, but no logs produced & no response to trigger by onCreate() event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM