Dealing with session expiration in a React app

I need to have the UI reflect the logged in state at all times. useSession will not trigger if a session expires (see: https://discord.com/channels/1288403910284935179/1353810672458403920/1353820038154551469)

I'm trying to figure out how to deal with this, here's my current plan:

  1. Store the current session in a React context. Keep it updated for sign in / sign out via useSession.
  2. When I get a 401 back from my server, that probably means the session has expired, call getSession and update the context.
Anyone have a better idea?

(tagging this with Next.js but I think it should apply to all React apps)
Was this page helpful?