Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/core/src/storage/sovranStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -119,6 +139,7 @@ export class SovranStorage implements Storage {
});
},
};

readonly userInfo = {
get: () => this.userInfoStore.getState().userInfo,
onChange: (callback: (value: UserInfoState) => void) =>
Expand Down