Keeping user logged in between browser refreshes (or: how to stringify authClient/agent/actor)

Goes to show you how little web dev experience I have; this is the first I’ve heard of IndexedDb. Seems like that’s exactly what I’m looking for: a way to store non-serializable objects in [something like] localStorage.

I assume that by “already handled”, you mean that, assuming I want to avoid persistence libraries, I can use the standard methods to interact with IndexedDb myself (like I would otherwise interact with localStorage), and just pass it an Identity object, not that there’s an easier way to just say “I want this object persisted across refreshes in IndexedDb”?

If I understand correctly, my workflow will be:

  • Check if Identity is in IndexedDb
    • If so, AuthClient.create(identity)
      • Check if authenticated
        • If so, create Actor using identity
        • If not, proceed as though identity wasn’t in IndexedDb
    • If not:
      • AuthClient.create()
      • authClient.login(…)
      • Store authClient.getIdentity() in IndexedDb
      • create Actor using identity

In writing this post, I noticed that there’s a “storage” parameter for AuthClient.create that defaults to localStorage. If AuthClient can be persisted in localStorage, maybe my first step above can be simplified to not even require the identity, and to just use whatever was persisted.