electric-sql / electric

Sync little subsets of your Postgres data into local apps and services.
https://electric-sql.com
Apache License 2.0
6.47k stars 156 forks source link

examples: update gatekeeper auth client to use `onError`. #2028

Closed thruflo closed 3 hours ago

thruflo commented 22 hours ago

This is what I requested in https://github.com/electric-sql/electric/pull/2018#issuecomment-2491085763

The client now uses the new onError to handle 401/403 and reconnect with a new auth token.

One observation: with the onError being defined before the shape is instantiated, I'm not sure what the best control flow is to handle a 405 must refetch. Certainly it's hard to handle in the onError callback. I guess this is what's being discussed in https://github.com/electric-sql/electric/issues/1997 etc.

netlify[bot] commented 22 hours ago

Deploy Preview for electric-next ready!

Name Link
Latest commit 65269be279a56d4c0c16807ac2d36831a83e91ba
Latest deploy log https://app.netlify.com/sites/electric-next/deploys/673f71e2f222740008457bd7
Deploy Preview https://deploy-preview-2028--electric-next.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

KyleAMathews commented 22 hours ago

409 must-refetch responses never would reach onErrorhttps://github.com/electric-sql/electric/blob/e9813969dccb679ab763773205f59a3fe7166bdc/packages/typescript-client/src/client.ts#L371-L377

thruflo commented 22 hours ago

So the stream handles it and the shape gets the instruction in a control message?

Makes sense, cool.

KyleAMathews commented 22 hours ago

So the stream handles it and the shape gets the instruction in a control message?

yeah exactly — the shape just resets its materialized view and recreates it — subscribers would never notice