Merge pull request #8832 from streetwriters/fix-vault-biometrics-unlock

mobile: fix vault biometrics state incorrect on app launch
This commit is contained in:
Ammar Ahmed
2025-10-23 13:47:09 +05:00
committed by GitHub
2 changed files with 9 additions and 6 deletions

View File

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

View File

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