fix(auth): add dispose method to cleanup BroadcastChannel
Summary
Adds a dispose() method to GoTrueClient to properly clean up the BroadcastChannel event listener and close the channel.
Problem
In GoTrueClient, a BroadcastChannel is created with an event listener in the constructor, but there's no way to remove the listener or close the channel. The cleanup pattern exists for visibilityChangedCallback (via _removeVisibilityChangedCallback()) but was missed for BroadcastChannel.
Location: packages/core/auth-js/src/GoTrueClient.ts (~line 398)
Solution
- Store callback reference in
broadcastChannelCallbackproperty - Add private
_removeBroadcastChannel()method (matches existing pattern) - Add public
dispose()method for full resource cleanup
Changes
-
GoTrueClient.ts: AddedbroadcastChannelCallbackproperty,_removeBroadcastChannel(), anddispose()methods -
GoTrueClient.browser.test.ts: Added test for dispose cleanup
Related
Closes #2020
coverage: 81.023% (+0.03%) from 80.997% when pulling 9bf0ecd63246ab4fb517deb30a1bcdafaceafa0b on 7ttp:fix/auth-broadcastchannel-cleanup into 09aa10628b00cbdf65ace0f9e8e79237e7c0c1dc on supabase:master.
@mandarini
Hi @7ttp ! Thank you for the PR! I discussed it with the auth team and we decided that we will not be merging this PR. We do not see the reason why this needs cleaning. The general opinion is that it doesn’t solve a real problem, but in fact it may create more because someone will try to use it properly, fail, and then be “why isn’t X working”.
Thank you for contributing though! 💚