Closed strugee closed 1 year ago
Hi @strugee, your usecase makes sense, the overall idea of logout is that storage is naturally replaced by the results of getFlags. Logout can clear storage however it is worth noting that cross platform storage is async.
It sounds like regardless, the solution here is to make logout async. Would your case be resolved if you could await flagsmith.logout and it resolves when the cache is populated by environment flags? This would mean the next session would not have to await an initial getFlags when cache is enabled.
Sorry for the delay here - I totally thought I responded. Yeah, that sounds like it would resolve my use case!
Hi, actually looking at the SDK what I said is already true, flagsmith.logout is async as defined by the types and awaits flagsmith.getFlags() https://github.com/Flagsmith/flagsmith-js-client/blob/main/flagsmith-core.ts#L690
Please feel free to reopen if awaiting logout doesn't work for you
The problem with awaiting logout()
is that it incurs an additional request/response cycle of latency to the logout action, whereas otherwise the page would just immediately refresh and render the logged-out view.
But again, quoting from the description:
Note that this isn't a priority for us since we've determined that for our particular use case this doesn't matter, but it does seem suboptimal!
I guess if no one else has complained it's probably fine 🤷
I'm currently integrating Flagsmith into my company's frontend React app. I wanted to automatically identify users to Flagsmith when they log in, and subsequently unidentify them with
logout()
when they log out. However, I discovered that in order to log users out, our app currently does a request to the backend and then doeswindow.location.replace('/')
, which triggers an actual page navigation event (as opposed to apushState()
React routing event). Importantly, we also have local storage caching enabled.The problem is that this races the request kicked off by
getFlags()
in the logout method. This means that (if the right request wins the race):logout()
gets called.As such it would be nice if
logout()
could automatically invalidate these cache entries - it's difficult to imagine a use case where you'd want to keep them (maybe if you just never used segment overrides or something like that I guess?) but if there's concerns there could also be just a "clear cache" method so the SDK consumer could manually do this themselves.Note that this isn't a priority for us since we've determined that for our particular use case this doesn't matter, but it does seem suboptimal!