Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: subscribe to user related events before fetching user

Abdullah Atta717750d5d4d2
diff --git a/apps/web/src/stores/user-store.ts b/apps/web/src/stores/user-store.ts
index ea83dc907..1eb224184 100644
--- a/apps/web/src/stores/user-store.ts
+++ b/apps/web/src/stores/user-store.ts
@@ -59,46 +59,44 @@ class UserStore extends BaseStore<UserStore> {
if (Config.get("sessionExpired")) return;
- return db.user.fetchUser().then(async (user) => {
- if (!user) return false;
-
- this.set({
- user,
- isLoggedIn: true
+ EV.subscribe(EVENTS.userSubscriptionUpdated, (subscription) => {
+ const wasUserPremium = isUserPremium();
+ this.set((state) => {
+ if (!state.user) return;
+ state.user.subscription = subscription;
});
+ if (!wasUserPremium && isUserPremium())
+ OnboardingDialog.show({
+ type:
+ subscription.type === SUBSCRIPTION_STATUS.TRIAL ? "trial" : "pro"
+ });
+ });
- EV.remove(EVENTS.userSubscriptionUpdated, EVENTS.userEmailConfirmed);
+ EV.subscribe(EVENTS.userEmailConfirmed, () => {
+ hashNavigate("/confirmed");
+ });
- EV.subscribe(EVENTS.userSubscriptionUpdated, (subscription) => {
- const wasUserPremium = isUserPremium();
- this.set((state) => {
- if (!state.user) return;
- state.user.subscription = subscription;
- });
- if (!wasUserPremium && isUserPremium())
- OnboardingDialog.show({
- type:
- subscription.type === SUBSCRIPTION_STATUS.TRIAL ? "trial" : "pro"
- });
+ EV.subscribe(EVENTS.userLoggedOut, async (reason) => {
+ this.set((state) => {
+ state.user = undefined;
+ state.isLoggedIn = false;
});
+ config.clear();
+ if (reason) {
+ await ConfirmDialog.show({
+ title: "You were logged out",
+ message: reason,
+ negativeButtonText: "Okay"
+ });
+ }
+ });
- EV.subscribe(EVENTS.userEmailConfirmed, () => {
- hashNavigate("/confirmed");
- });
+ return db.user.fetchUser().then(async (user) => {
+ if (!user) return false;
- EV.subscribe(EVENTS.userLoggedOut, async (reason) => {
- this.set((state) => {
- state.user = undefined;
- state.isLoggedIn = false;
- });
- config.clear();
- if (reason) {
- await ConfirmDialog.show({
- title: "You were logged out",
- message: reason,
- negativeButtonText: "Okay"
- });
- }
+ this.set({
+ user,
+ isLoggedIn: true
});
return true;