Skip to content

Instantly share code, notes, and snippets.

View dooart's full-sized avatar

Thiago Duarte dooart

View GitHub Profile
@dooart
dooart / README.md
Created March 2, 2025 01:19 — forked from Cikmo/README.md
Connection handler that keeps Supabase Realtime channels alive. It automatically reconnects after errors, handles reauthentication, and more.

I had some issues getting a reliable connection up. Made this after a lot of experimentation and it now works well.

Includes how to keep the connection alive when the document is not visible, handles reconnecting on errors, and also fixes certain authentication issues when coming back to a document that has not been visible while the token expired.

To use it, you pass in a factory function for your RealtimeChannel. Do not call .subscribe() on the channel, the handler will do this for you. See example.

PS: If you're not using supabase-js you'll need to change stuff a bit. Instead of passing in SupabaseClient switch it to use RealtimeClient, and update the refreshSessionIfNeeded method to your authentication implementation.

If you see any problems or have suggestions for improvements, please leave a comment.

@dooart
dooart / keybase.md
Created October 10, 2017 08:40
🐙

Keybase proof

I hereby claim:

  • I am dooart on github.
  • I am dooart (https://keybase.io/dooart) on keybase.
  • I have a public key ASClmNxeqbC3gPTOFpiqU1up79-Xl8dbehF_g-2FWEheEwo

To claim this, I am signing this object: