Skip to content

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

web: fix features reset on subscription change

Abdullah Attaebd9b45cac79
diff --git a/apps/web/src/common/index.ts b/apps/web/src/common/index.ts
index e32f5dc9f..4a29ed0f0 100644
--- a/apps/web/src/common/index.ts
+++ b/apps/web/src/common/index.ts
@@ -61,6 +61,7 @@ import { MenuItem } from "@notesnook/ui";
import { showFeatureNotAllowedToast } from "./toasts";
import { UpgradeDialog } from "../dialogs/buy-dialog/upgrade-dialog";
import { setToolbarPreset } from "./toolbar-config";
+import { useKeyStore } from "../interfaces/key-store";
export const CREATE_BUTTON_MAP = {
notes: {
@@ -512,8 +513,12 @@ export async function resetFeatures() {
"defaultSidebarTab",
"disableTrashCleanup",
"syncControls",
- "fullOfflineMode"
+ "fullOfflineMode",
+ "appLock"
]);
+ if (!features.appLock.isAllowed) {
+ await useKeyStore.getState().disable();
+ }
if (!features.customHomepage.isAllowed)
useSettingStore.getState().setHomepage();
diff --git a/apps/web/src/interfaces/key-store.ts b/apps/web/src/interfaces/key-store.ts
index eba2c123e..75b270e43 100644
--- a/apps/web/src/interfaces/key-store.ts
+++ b/apps/web/src/interfaces/key-store.ts
@@ -270,14 +270,19 @@ class KeyStore extends BaseStore<KeyStore> {
throw e;
});
if (options?.permanent) {
- await this.resetCredentials();
- await this.storeKey(key);
- this.#key = undefined;
+ await this.disable();
} else this.#key = key;
this.set({ isLocked: false });
};
+ disable = async () => {
+ if (!this.#key) return;
+ await this.resetCredentials();
+ await this.storeKey(this.#key);
+ this.#key = undefined;
+ };
+
relock = () => {
this.#key = undefined;
this.set({ isLocked: true });
diff --git a/apps/web/src/stores/user-store.ts b/apps/web/src/stores/user-store.ts
index 7b6721944..8e6fcb872 100644
--- a/apps/web/src/stores/user-store.ts
+++ b/apps/web/src/stores/user-store.ts
@@ -28,6 +28,7 @@ import { ConfirmDialog } from "../dialogs/confirm";
import { OnboardingDialog } from "../dialogs/onboarding-dialog";
import { strings } from "@notesnook/intl";
import { isUserSubscribed } from "../hooks/use-is-user-premium";
+import { resetFeatures } from "../common";
class UserStore extends BaseStore<UserStore> {
isLoggedIn?: boolean;
@@ -65,6 +66,7 @@ class UserStore extends BaseStore<UserStore> {
state.user.subscription = subscription;
});
if (!wasSubscribed && isUserSubscribed()) OnboardingDialog.show({});
+ resetFeatures();
});
EV.subscribe(EVENTS.userEmailConfirmed, () => {
diff --git a/apps/web/src/views/app-lock.tsx b/apps/web/src/views/app-lock.tsx
index b3fe5ba23..7e6c16964 100644
--- a/apps/web/src/views/app-lock.tsx
+++ b/apps/web/src/views/app-lock.tsx
@@ -69,12 +69,7 @@ export default function AppLock(props: PropsWithChildren<unknown>) {
await useKeyStore
.getState()
- .unlock(
- { ...credential, password },
- {
- permanent: !(await isFeatureAvailable("appLock")).isAllowed
- }
- )
+ .unlock({ ...credential, password })
.catch((e) => {
setError(
typeof e === "string"
diff --git a/packages/core/src/api/user-manager.ts b/packages/core/src/api/user-manager.ts
index 0d9a856fb..8ab3cc5c4 100644
--- a/packages/core/src/api/user-manager.ts
+++ b/packages/core/src/api/user-manager.ts
@@ -354,6 +354,7 @@ class UserManager {
);
if (user) {
const oldUser = await this.getUser();
+ await this.setUser(user);
if (
oldUser &&
(oldUser.subscription.plan !== user.subscription.plan ||
@@ -365,7 +366,6 @@ class UserManager {
}
if (oldUser && !oldUser.isEmailConfirmed && user.isEmailConfirmed)
EV.publish(EVENTS.userEmailConfirmed);
- await this.setUser(user);
EV.publish(EVENTS.userFetched, user);
return user;
} else {