Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Broadcast auth events to other tabs on web #1005

Merged
merged 11 commits into from
Sep 20, 2024

Conversation

Vinzent03
Copy link
Collaborator

@Vinzent03 Vinzent03 commented Aug 15, 2024

What kind of change does this PR introduce?

feature

What is the current behavior?

When singing in or out in a tab on flutter web, the other tabs of the same domain are untouched.

What is the new behavior?

Every auth event and their session is distributed to the other tabs via the web broadcast channel feature. The js library does this as well.

I've noticed that auth-js doesn't contain the userDeleted event, but found no use in our library as well. It got added here, but I don't see why. So I marked it as deprecated.

Furthermore, from what I see, the auth refresh token and streams got nowhere closed, so I added a dispose() method and call it from the dispose method in the supabase package.

Additional context

close #979

@Vinzent03 Vinzent03 changed the title feat: broadcast auth events on web feat: Broadcast auth events to other tabs on web Aug 16, 2024
@Vinzent03 Vinzent03 marked this pull request as ready for review August 16, 2024 20:39
@Vinzent03
Copy link
Collaborator Author

Vinzent03 commented Aug 16, 2024

I couldn't find a way to do automated testing for this. I only tested this manually with a little modified flutter example app. I didn't test the compatibility with the js package as well. Maybe you have a ready to go setup for a flutter and js app on the same domain.

The auth-js doesn't have this, but I think it would be useful to add a fromBroadcast or so to AuthState to let the listener know whether the event actually comes from the current instance or not. One might listen for auth events and do some api requests, which are only necessary to be done from the origin tab.

Copy link
Member

@dshukertjr dshukertjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a screen recording that shows how this PR works?

@Vinzent03
Copy link
Collaborator Author

I do not currently, but I'm unsure how that helps you. I've added logging to the onAuthStateChange stream and saw that when I log in in one tab, the other tabs received the same AuthState event.

@dshukertjr
Copy link
Member

I'm unsure how that helps you

I want to verify the behavior. It would be awesome if you could do a quick screen recording verifying that this PR works as intended.

@Vinzent03
Copy link
Collaborator Author

I tried a different example app and indeed found the issue of not properly saving the session if it's null. Should be fixed now. Here's the recording as well:
https://github.com/user-attachments/assets/8a515a16-1dc2-4ff0-9328-29a8e5e1c998

Copy link
Member

@dshukertjr dshukertjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the awesome PR! Just had a few small questions, but it looks amazing and sorry for taking time to get back to this one.

packages/gotrue/lib/src/gotrue_client.dart Outdated Show resolved Hide resolved
packages/gotrue/lib/src/gotrue_client.dart Outdated Show resolved Hide resolved
packages/gotrue/lib/src/gotrue_client.dart Outdated Show resolved Hide resolved
packages/gotrue/lib/src/gotrue_client.dart Outdated Show resolved Hide resolved
packages/gotrue/lib/src/gotrue_client.dart Show resolved Hide resolved
packages/gotrue/lib/src/types/auth_state.dart Outdated Show resolved Hide resolved
@Vinzent03 Vinzent03 merged commit 8f473f1 into main Sep 20, 2024
9 checks passed
@Vinzent03 Vinzent03 deleted the feat/broadcast-auth-events branch September 20, 2024 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Users are not getting logged out across tabs on web
3 participants