web: fix features reset on subscription change

This commit is contained in:
Abdullah Atta
2025-10-02 11:17:08 +05:00
parent 5ae024f20a
commit ebd9b45cac
5 changed files with 18 additions and 11 deletions

View File

@@ -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();

View File

@@ -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 });

View File

@@ -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, () => {

View File

@@ -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"

View File

@@ -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 {