diff --git a/packages/core/src/storage/sovranStorage.ts b/packages/core/src/storage/sovranStorage.ts index 674aa0c7f..02cafed99 100644 --- a/packages/core/src/storage/sovranStorage.ts +++ b/packages/core/src/storage/sovranStorage.ts @@ -61,11 +61,31 @@ export class SovranStorage implements Storage { this.userInfoStore = createStore( { userInfo: INITIAL_VALUES.userInfo }, { - persist: { storeId: `${this.storeId}-userInfo` }, + persist: { + storeId: `${this.storeId}-userInfo`, + }, } ); + + this.fixAnonymousId(); } + /** + * This is a fix for users that have started the app with the anonymousId set to 'anonymousId' bug + */ + private fixAnonymousId = () => { + const fixUnsubscribe = this.userInfoStore.subscribe((store) => { + if (store.userInfo.anonymousId === 'anonymousId') { + this.userInfoStore.dispatch((state) => { + return { + userInfo: { ...state.userInfo, anonymousId: getUUID() }, + }; + }); + } + fixUnsubscribe(); + }); + }; + readonly isReady = { get: () => true, onChange: (_callback: (value: boolean) => void) => { @@ -119,6 +139,7 @@ export class SovranStorage implements Storage { }); }, }; + readonly userInfo = { get: () => this.userInfoStore.getState().userInfo, onChange: (callback: (value: UserInfoState) => void) =>