[英]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这样你就可以
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.