lijim / monks-and-mages

Monks and Mages is a TCG-game built on React and socket.io
https://www.monksandmages.com
MIT License
17 stars 0 forks source link

Fix: mitigate stale connections issue #435

Closed lijim closed 1 year ago

lijim commented 1 year ago

Problem Normally, a connected user looks like this:

Screen Shot 2023-03-29 at 10 31 59 PM

But sometimes, a user can get in a state where they have a sessionID still remembered in local storage, without proper auth0 cookies and we wind up in this state:

Screen Shot 2023-03-29 at 10 31 52 PM

This is annoying to deal with as we debug because it's hard to tell if the user is logged in at a first glance (they're half-logged in in the sense that the game server remembers their sessionID, but they lack auth0 authentication, so they'll lack avatar setting / saved deck selections, etc.)

Solution 1.) Although it's not efficient, I made all the SWR fetcher's function factories that generate each time the components re-renders. This mitigates an issue where sometimes the components render and don't have access to the cookie yet, necessitating a refresh. The idea here is that the cookie will be retrieved 2.) Added a login button for users partially logged in:

Screen Shot 2023-03-29 at 10 36 23 PM