Enforcing one auth session at a time... gracefully?

We’re doing a livestream and want to make sure an authenticated user can only stream from one device (i.e. not sharing login for others to watch).

I can imagine a brute, inflexible way of doing it - saving active sessions and checking that list when accessing the streaming page. But sthe UX is pretty awful. You start watching on your phone, want to switch to your computer… you have to log out or navigate away from the page on your phone first?

Ideally I’d love a solution where a second instance issues a pop up saying “Do you want to watch here?” with yes closing out the original session. But that would require websockets, no?

Any ideas/advice would be very appreciated!

Mitch

I feel like supabase could probably handle this using real-time tables.

When a user starts a session/video you’d set a variable in the app and on the user to a random value. If those 2 are equal, stream the video. Else, stop the stream and redirect the user.

A basic outline of how you could accomplish this.

supabase released enforced single session per user a week ago

1 Like

Thanks all, appreciate it!