Skip to content

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

mobile: fix vault biometrics state incorrect on app launch

Ammar Ahmedd51aaa8eb1f4
diff --git a/apps/mobile/app/hooks/use-vault-status.ts b/apps/mobile/app/hooks/use-vault-status.ts
index 3d52b0029..4bb57d7c0 100644
--- a/apps/mobile/app/hooks/use-vault-status.ts
+++ b/apps/mobile/app/hooks/use-vault-status.ts
@@ -21,6 +21,7 @@ import React, { useCallback, useEffect } from "react";
import { db } from "../common/database";
import BiometricService from "../services/biometrics";
import { eSubscribeEvent, eUnSubscribeEvent } from "../services/event-manager";
+import { useSettingStore } from "../stores/use-setting-store";
const VaultStatusDefaults = {
exists: false,
@@ -36,6 +37,7 @@ export type VaultStatusType = {
export const useVaultStatus = () => {
const [vaultStatus, setVaultStatus] = React.useState(VaultStatusDefaults);
+ const isAppLoading = useSettingStore((state) => state.isAppLoading);
const checkVaultStatus = useCallback(() => {
db.vault?.exists().then(async (exists) => {
@@ -50,12 +52,13 @@ export const useVaultStatus = () => {
}, []);
useEffect(() => {
+ if (isAppLoading) return;
checkVaultStatus();
eSubscribeEvent("vaultUpdated", () => checkVaultStatus());
return () => {
eUnSubscribeEvent("vaultUpdated", () => checkVaultStatus());
};
- }, [checkVaultStatus]);
+ }, [checkVaultStatus, isAppLoading]);
return vaultStatus;
};
diff --git a/apps/mobile/app/screens/editor/index.tsx b/apps/mobile/app/screens/editor/index.tsx
index 9da23b5cc..8733a4838 100755
--- a/apps/mobile/app/screens/editor/index.tsx
+++ b/apps/mobile/app/screens/editor/index.tsx
@@ -61,6 +61,7 @@ import {
import { fluidTabsRef } from "../../utils/global-refs";
import { strings } from "@notesnook/intl";
import { i18n } from "@lingui/core";
+import { useVaultStatus } from "../../hooks/use-vault-status";
const style: ViewStyle = {
height: "100%",
@@ -197,6 +198,7 @@ const Editor = React.memo(
export default Editor;
const useLockedNoteHandler = () => {
+ const vaultStatus = useVaultStatus();
const tab = useTabStore((state) => state.getTab(state.currentTab));
const tabRef = useRef(tab);
tabRef.current = tab;
@@ -217,15 +219,13 @@ const useLockedNoteHandler = () => {
useEffect(() => {
(async () => {
- const biometry = await BiometricService.isBiometryAvailable();
- const fingerprint = await BiometricService.hasInternetCredentials();
useTabStore.setState({
- biometryAvailable: !!biometry,
- biometryEnrolled: !!fingerprint
+ biometryAvailable: !!vaultStatus.isBiometryAvailable,
+ biometryEnrolled: !!vaultStatus.biometryEnrolled
});
syncTabs("biometry");
})();
- }, [tab?.id]);
+ }, [tab?.id, vaultStatus.biometryEnrolled, vaultStatus.isBiometryAvailable]);
useEffect(() => {
const unlockWithBiometrics = async () => {