# Ember Simple Auth session store

**URL:** <https://discuss.emberjs.com/t/ember-simple-auth-session-store/21389>\
**Category:** Data Modeling\
**Created:** [December 3, 2024, 4:10pm UTC](https://discuss.emberjs.com/t/ember-simple-auth-session-store/21389 "2024-12-03T16:10:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![spphashicorp](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@spphashicorp](https://discuss.emberjs.com/u/spphashicorp)\
**Post date:** [December 3, 2024, 4:10pm UTC](https://discuss.emberjs.com/t/ember-simple-auth-session-store/21389/1 "2024-12-03T16:10:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dknutsen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dknutsen/32/16471_2.png) [@dknutsen](https://discuss.emberjs.com/u/dknutsen)\
**Post date:** [December 6, 2024, 3:40pm UTC](https://discuss.emberjs.com/t/ember-simple-auth-session-store/21389/2 "2024-12-06T15:40:51Z")

</div>

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](https://github.com/mainmatter/ember-simple-auth/blob/f7513009562573a2fd1165cead2a9b71628e4ee6/packages/ember-simple-auth/src/initializers/ember-simple-auth.js#L16) is the ember-simple-auth initializer which might give you some clues as to exactly what to do for the latter two cases.

---

<div class="post-metadata">

**Author:** ![spphashicorp](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@spphashicorp](https://discuss.emberjs.com/u/spphashicorp)\
**Post date:** [December 6, 2024, 4:20pm UTC](https://discuss.emberjs.com/t/ember-simple-auth-session-store/21389/3 "2024-12-06T16:20:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dknutsen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dknutsen/32/16471_2.png) [@dknutsen](https://discuss.emberjs.com/u/dknutsen)\
**Post date:** [December 6, 2024, 4:36pm UTC](https://discuss.emberjs.com/t/ember-simple-auth-session-store/21389/4 "2024-12-06T16:36:46Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![dknutsen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dknutsen/32/16471_2.png) [@dknutsen](https://discuss.emberjs.com/u/dknutsen)\
**Post date:** [December 6, 2024, 4:39pm UTC](https://discuss.emberjs.com/t/ember-simple-auth-session-store/21389/5 "2024-12-06T16:39:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![spphashicorp](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@spphashicorp](https://discuss.emberjs.com/u/spphashicorp)\
**Post date:** [December 6, 2024, 7:21pm UTC](https://discuss.emberjs.com/t/ember-simple-auth-session-store/21389/6 "2024-12-06T19:21:17Z")

</div>

> [@dknutsen](#):
>
> try to update the registration of the `session-store:application` at runtime based on the LD flag

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 🙂 thanks!
