Ember Simple Auth session store

Is there a way to conditionally set the session store for ember-simple-auth? for example via a launch darkly flag? Basically, depending on the condition, it should be either a BaseStore or an AdaptiveStore.

At what point do you want to swap the store? I think that kinda determines what the best solution is. I’m not sure how you are using launch darkly so it’s difficult to say.

Options would be:

  • build time: should be pretty easy to do this
  • app “boot time”: could probably use an initializer and make sure it runs before any of the simple auth stuff
  • app runtime: not sure on the best strategy offhand but one option might be to hack around wtih the registry

This is the ember-simple-auth initializer which might give you some clues as to exactly what to do for the latter two cases.

I tried an initializer, but I ran into an issue because launch darkly wasn’t initialized at that point, and therefore trying to retrieve a variation was not feasible. So ideally, I need to do this once i can read the flag.

yeah that was kinda my guess is that LD would be initialized after boot. In that case the main two ideas I can think of would be:

  • try to update the registration of the session-store:application at runtime based on the LD flag
  • create a custom session store class which frankensteins code from both of the ones you want to use and uses different logic based on the LD flag (which could be injected via a service or whatever).
1 Like

Trying to update the registration at runtime might be weird, I’m not sure if ESA will like having that changed after initialization or if there’s state you’d have to migrate/move from one store to the other if you’re booting the app with one and then “swapping” it.

You could also try to force LD code to be initialized earlier so the app can boot with LD state already determined, but not sure if there are performance or stability consequences to that given it’s a 3rd party service.

1 Like

I haven’t tried that yet; I tried setting this.store but it told me that store is read-only. Will try to overwrite the session-store:application registration and keep you posted :slight_smile: thanks!