fix(supabase): avoid dropping realtime auth to manual mode on client init - #2464
fix(supabase): avoid dropping realtime auth to manual mode on client init#2464hmnd wants to merge 4 commits into
Conversation
mandarini
left a comment
There was a problem hiding this comment.
Hi @hmnd, thank you so much for contributing to Supabase! This is a great catch, and the root cause diagnosis is spot on. Confirmed that setAuth(token) with an explicit value flips realtime into manual mode for good, which is exactly why refresh was getting stuck for custom JWT callbacks. Really appreciate you digging into this instead of just settling for the workaround from #1304.
Two small things before we merge:
- Could you add a
.catch()back on thethis.realtime.setAuth()call in the constructor? Right now a failure there would be an unhandled promise rejection rather than a caught error. - A few months ago we specifically wrapped this same call in
Promise.resolve()to fix a Firefox extension cross-context Promise error (#2033). Since this PR removes that wrap, could you double check (or let us know your reasoning on) whether that issue could resurface here?
Thank you again for taking the time to fix this properly instead of just leaving the workaround in place. Contributions like this are what keep our SDKs solid.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
Assessment against linked issues
Possibly related PRs
Suggested labels: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@mandarini thanks for the review! Regarding your comments:
|
🔍 Description
When using a custom callback for
accessTokenonSupabaseClient, realtime gets stuck on the access token initially set during init, rather than refreshing from the callback as expected.What changed?
I've replaced the previous approach of manually requesting the accesstoken inside
SupabaseClient's constructor with an empty call torealtime.setAuth(). This way realtime retrieves and sets the access token on its own, without dropping to manual mode.Why was this change needed?
I ran into this issue with my custom minted jwts. I found #1304, in which the fix was to manually call
supabase.realtime.setAuth()with no args to re-enable callback mode for access tokens.I also couldn't find any documentation advising users of custom tokens that they must always call do this after client init, making for poor UX and confusing bugs.
Closes #1304
🔄 Breaking changes
Technically not a breaking change but, with this change, we do lose the
Failed to set initial Realtime auth tokenerror message if theaccessTokenfunction throws, because realtime's setAuth has its own error handling.📋 Checklist
<type>(<scope>): <description>pnpm nx formatto ensure consistent code formatting📝 Additional notes
#1304 really shouldn't have been closed and that is what frustrates me about stale bots. I would kindly suggest reconsidering the repo's usage of stale bot, or altering its config to eg. re-open issues if commented on after auto-close.