A firebase functionfirebase functionCloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. that is called from firebase with the updated note data through a database webhook. This function updates the note within firebase from supabase.

  1. With the updated note data from the supabase, a query is made to supabase for the same note within firebase
  2. If the note from supabase was modified_at later than the note from firebase, then we skip the following steps.
  3. Otherwise, upsert the updated note into supabase from firebase.
exports.supabase_notes_to_firebase = functions.https.onRequest(async (req, res) => {
  const note = req.body.record;
  const fireNote = supabaseNoteToFirebase(note);
  const ref = db.collection('notes').doc(;
  const snapshot = await ref.get();
  const prevNote =;
  if (!prevNote || prevNote.last_modified_timestamp.toDate() < fireNote.last_modified_timestamp) {
    await ref.set(fireNote);`updated note: ${}`)
    return res.sendStatus(200);
  return res.sendStatus(400)