A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: fix vault unlock with biometrics
Ammar Ahmed62dd5a5416d3
diff --git a/apps/mobile/app/components/dialogs/applock-password/index.tsx b/apps/mobile/app/components/dialogs/applock-password/index.tsxindex 8c6796ecc..09c23f2f3 100644--- a/apps/mobile/app/components/dialogs/applock-password/index.tsx+++ b/apps/mobile/app/components/dialogs/applock-password/index.tsx@@ -24,7 +24,7 @@ import {setAppLockVerificationCipher,validateAppLockPassword} from "../../../common/database/encryption";-import BiometicService from "../../../services/biometrics";+import BiometricService from "../../../services/biometrics";import { DDS } from "../../../services/device-detection";import {ToastManager,@@ -323,7 +323,7 @@ export const AppLockPassword = () => {SettingsService.setProperty("appLockHasPasswordSecurity", false);if (- !(await BiometicService.isBiometryAvailable()) ||+ !(await BiometricService.isBiometryAvailable()) ||SettingsService.getProperty("biometricsAuthEnabled") === false) {SettingsService.setProperty("appLockEnabled", false);diff --git a/apps/mobile/app/components/dialogs/vault/index.js b/apps/mobile/app/components/dialogs/vault/index.jsindex a67561579..d1fb90e2a 100644--- a/apps/mobile/app/components/dialogs/vault/index.js+++ b/apps/mobile/app/components/dialogs/vault/index.js@@ -128,7 +128,7 @@ export class VaultDialog extends Component {: this.state.copyNote? "Unlock note to copy it. If biometrics are not working, you can enter device pin to unlock vault.": this.state.goToEditor- ? "Unlock note to open it in editor. If biometrics are not working, you can enter device pin to unlock vault."+ ? "Unlock note to open it in editor.": "Enter vault password to unlock note. If biometrics are not working, you can enter device pin to unlock vault.": "Enter vault password to lock note. If biometrics are not working, you can enter device pin to lock note.");}diff --git a/apps/mobile/app/hooks/use-app-events.tsx b/apps/mobile/app/hooks/use-app-events.tsxindex 03c932a37..aab39827a 100644--- a/apps/mobile/app/hooks/use-app-events.tsx+++ b/apps/mobile/app/hooks/use-app-events.tsx@@ -85,7 +85,6 @@ import { SyncStatus, useUserStore } from "../stores/use-user-store";import { updateStatusBarColor } from "../utils/colors";import { BETA } from "../utils/constants";import {- eClearEditor,eCloseSheet,eLoginSessionExpired,eOnLoadNote,@@ -532,12 +531,6 @@ export const useAppEvents = () => {//@ts-ignoreglobalThis["IS_SHARE_EXTENSION"] = false;} else {- const id = useTabStore.getState().getCurrentNoteId();- const note = id ? await db.notes.note(id) : undefined;- const locked = note && (await db.vaults.itemExists(note));- if (locked && SettingsService.canLockAppInBackground()) {- eSendEvent(eClearEditor);- }await saveEditorState();if (SettingsService.canLockAppInBackground() &&diff --git a/apps/mobile/app/hooks/use-vault-status.ts b/apps/mobile/app/hooks/use-vault-status.tsindex 07d1767b5..a5add986d 100644--- a/apps/mobile/app/hooks/use-vault-status.ts+++ b/apps/mobile/app/hooks/use-vault-status.ts@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import React, { useCallback, useEffect } from "react";-import BiometicService from "../services/biometrics";+import BiometricService from "../services/biometrics";import { eSubscribeEvent, eUnSubscribeEvent } from "../services/event-manager";import { db } from "../common/database";@@ -39,8 +39,8 @@ export const useVaultStatus = () => {const checkVaultStatus = useCallback(() => {db.vault?.exists().then(async (exists) => {- const available = await BiometicService.isBiometryAvailable();- const fingerprint = await BiometicService.hasInternetCredentials();+ const available = await BiometricService.isBiometryAvailable();+ const fingerprint = await BiometricService.hasInternetCredentials();if (VaultStatusCache.exists === exists &&VaultStatusCache.biometryEnrolled === fingerprint &&diff --git a/apps/mobile/app/screens/editor/index.tsx b/apps/mobile/app/screens/editor/index.tsxindex 159ac7afa..eac9df275 100755--- a/apps/mobile/app/screens/editor/index.tsx+++ b/apps/mobile/app/screens/editor/index.tsx@@ -32,7 +32,7 @@ import WebView from "react-native-webview";import { ShouldStartLoadRequest } from "react-native-webview/lib/WebViewTypes";import { notesnook } from "../../../e2e/test.ids";import { db } from "../../common/database";-import BiometicService from "../../services/biometrics";+import BiometricService from "../../services/biometrics";import {ToastManager,eSendEvent,@@ -208,8 +208,8 @@ const useLockedNoteHandler = () => {useEffect(() => {(async () => {- const biometry = await BiometicService.isBiometryAvailable();- const fingerprint = await BiometicService.hasInternetCredentials();+ const biometry = await BiometricService.isBiometryAvailable();+ const fingerprint = await BiometricService.hasInternetCredentials();useTabStore.setState({biometryAvailable: !!biometry,biometryEnrolled: !!fingerprint@@ -223,9 +223,9 @@ const useLockedNoteHandler = () => {try {if (!tabRef.current?.noteLocked || !tabRef.current) return;console.log("Trying to unlock with biometrics...");- const credentials = await BiometicService.getCredentials(+ const credentials = await BiometricService.getCredentials("Unlock note",- "Unlock note to open it in editor. If biometrics are not working, you can enter device pin to unlock vault."+ "Unlock note to open it in editor.");if (credentials && credentials?.password && tabRef.current.noteId) {@@ -233,6 +233,7 @@ const useLockedNoteHandler = () => {tabRef.current.noteId,credentials?.password);+eSendEvent(eOnLoadNote, {item: note});@@ -269,7 +270,7 @@ const useLockedNoteHandler = () => {try {const unlocked = await db.vault.unlock(password);if (!unlocked) throw new Error("Incorrect vault password");- await BiometicService.storeCredentials(password);+ await BiometricService.storeCredentials(password);eSendEvent("vaultUpdated");ToastManager.show({heading: "Biometric unlocking enabled!",@@ -278,8 +279,8 @@ const useLockedNoteHandler = () => {context: "global"});- const biometry = await BiometicService.isBiometryAvailable();- const fingerprint = await BiometicService.hasInternetCredentials();+ const biometry = await BiometricService.isBiometryAvailable();+ const fingerprint = await BiometricService.hasInternetCredentials();useTabStore.setState({biometryAvailable: !!biometry,biometryEnrolled: !!fingerprintdiff --git a/apps/mobile/app/screens/settings/app-lock.js b/apps/mobile/app/screens/settings/app-lock.jsindex b3fe8be04..fed7dac04 100644--- a/apps/mobile/app/screens/settings/app-lock.js+++ b/apps/mobile/app/screens/settings/app-lock.js@@ -26,7 +26,7 @@ import { Pressable } from "../../components/ui/pressable";import Seperator from "../../components/ui/seperator";import Heading from "../../components/ui/typography/heading";import Paragraph from "../../components/ui/typography/paragraph";-import BiometicService from "../../services/biometrics";+import BiometricService from "../../services/biometrics";import { ToastManager, presentSheet } from "../../services/event-manager";import SettingsService from "../../services/settings";import { useSettingStore } from "../../stores/use-setting-store";@@ -119,7 +119,7 @@ const AppLock = () => {type={appLockMode === item.value ? "secondary" : "transparent"}onPress={async () => {if (- !(await BiometicService.isBiometryAvailable()) &&+ !(await BiometricService.isBiometryAvailable()) &&!useUserStore.getState().user &&item.value !== modes[0].value &&!SettingsService.getProperty("appLockHasPasswordSecurity")@@ -139,7 +139,7 @@ const AppLock = () => {) &&item.value !== modes[0].value) {- const verified = await BiometicService.validateUser(+ const verified = await BiometricService.validateUser("Verify it's you");if (verified) {diff --git a/apps/mobile/app/screens/settings/functions.js b/apps/mobile/app/screens/settings/functions.jsindex 9245f36e1..c3b744be3 100644--- a/apps/mobile/app/screens/settings/functions.js+++ b/apps/mobile/app/screens/settings/functions.js@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { db } from "../../common/database";import { validateAppLockPassword } from "../../common/database/encryption";import { presentDialog } from "../../components/dialog/functions";-import BiometicService from "../../services/biometrics";+import BiometricService from "../../services/biometrics";import { ToastManager } from "../../services/event-manager";import SettingsService from "../../services/settings";import { useUserStore } from "../../stores/use-user-store";@@ -100,9 +100,9 @@ export async function verifyUserWithApplock() {}});} else {- BiometicService.isBiometryAvailable().then((available) => {+ BiometricService.isBiometryAvailable().then((available) => {if (available) {- BiometicService.validateUser("Verify it's you").then((verified) => {+ BiometricService.validateUser("Verify it's you").then((verified) => {resolve(verified);});} else if (useUserStore.getState().user) {diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsxindex 909940f97..4f77be13b 100644--- a/apps/mobile/app/screens/settings/settings-data.tsx+++ b/apps/mobile/app/screens/settings/settings-data.tsx@@ -38,7 +38,7 @@ import { Update } from "../../components/sheets/update";import { VaultStatusType, useVaultStatus } from "../../hooks/use-vault-status";import { BackgroundSync } from "../../services/background-sync";import BackupService from "../../services/backup";-import BiometicService from "../../services/biometrics";+import BiometricService from "../../services/biometrics";import {ToastManager,eSendEvent,@@ -349,7 +349,7 @@ export const settingsGroups: SettingSection[] = [await db.user?.logout();setLoginMessage();await PremiumService.setPremiumStatus();- await BiometicService.resetCredentials();+ await BiometricService.resetCredentials();MMKV.clearStore();clearAllStores();refreshAllStores();@@ -394,7 +394,7 @@ export const settingsGroups: SettingSection[] = [if (verified) {eSendEvent("settings-loading", true);await db.user?.deleteUser(value);- await BiometicService.resetCredentials();+ await BiometricService.resetCredentials();SettingsService.set({introCompleted: true});@@ -789,7 +789,7 @@ export const settingsGroups: SettingSection[] = [}},{- id: "biometic-unlock",+ id: "biometric-unlock",type: "switch",name: "Biometric unlocking",icon: "fingerprint",@@ -859,13 +859,13 @@ export const settingsGroups: SettingSection[] = [if (!SettingsService.getProperty("appLockEnabled")) {if (!SettingsService.getProperty("appLockHasPasswordSecurity") &&- (await BiometicService.isBiometryAvailable())+ (await BiometricService.isBiometryAvailable())) {SettingsService.setProperty("biometricsAuthEnabled", true);}if (- !(await BiometicService.isBiometryAvailable()) &&+ !(await BiometricService.isBiometryAvailable()) &&!SettingsService.getProperty("appLockHasPasswordSecurity")) {ToastManager.show({diff --git a/apps/mobile/app/services/biometrics.ts b/apps/mobile/app/services/biometrics.tsindex b31069493..bda205fd9 100644--- a/apps/mobile/app/services/biometrics.ts+++ b/apps/mobile/app/services/biometrics.ts@@ -179,7 +179,7 @@ async function validateUser(title: string, description?: string) {}}-const BiometicService = {+const BiometricService = {isBiometryAvailable,enableFingerprintAuth,isFingerprintAuthEnabled,@@ -190,4 +190,4 @@ const BiometicService = {validateUser};-export default BiometicService;+export default BiometricService;diff --git a/apps/mobile/app/services/exporter.ts b/apps/mobile/app/services/exporter.tsindex 437832526..b233d1751 100644--- a/apps/mobile/app/services/exporter.ts+++ b/apps/mobile/app/services/exporter.ts@@ -40,7 +40,7 @@ import { basename, dirname, join } from "pathe";import downloadAttachment from "../common/filesystem/download-attachment";import { presentDialog } from "../components/dialog/functions";import { useSettingStore } from "../stores/use-setting-store";-import BiometicService from "./biometrics";+import BiometricService from "./biometrics";import { ToastManager } from "./event-manager";import { cacheDir } from "../common/filesystem/utils";@@ -186,10 +186,10 @@ async function exportAs(}async function unlockVault() {- const biometry = await BiometicService.isBiometryAvailable();- const fingerprint = await BiometicService.hasInternetCredentials();+ const biometry = await BiometricService.isBiometryAvailable();+ const fingerprint = await BiometricService.hasInternetCredentials();if (biometry && fingerprint) {- const credentials = await BiometicService.getCredentials(+ const credentials = await BiometricService.getCredentials("Unlock vault","Unlock vault to export locked notes");