Firebase Cloud Functions redirect on database trigger

1278 views firebase

One would normally redirect using an https trigger in Firebase Cloud Functions as below.

   exports.redirect = functions.https.onRequest((request, response) => {      

How do I achieve the same with a database trigger? I'd like to redirect on write to Firestore

exports.redirectTrigger = functions.firestore.document('companies/{userId}').onWrite((onWriteSnapshot) => {
      //Redirect here

answered question

1 Answer


The trigger comes from the database, which you can't redirect.

I think you may want to redirect the client that wrote to the database. There is no direct way to do this, as the database trigger is essentially unrelated to the client that triggered it.

So you'll need to open a back-channel for communication from your client function back to the client yourself. A typical way to do that would be to write a response into the same document, or in another document that the client can "predict" (e.g. a document with the same ID in a different collection).

posted this

Have an answer?


Please login first before posting an answer.