Skip to content

Commit

Permalink
web: ask for password when doing sensitive actions
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr authored and ammarahm-ed committed Sep 4, 2023
1 parent 9a31c07 commit 8c1629f
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions apps/web/src/dialogs/settings/backup-export-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export const BackupExportSettings: SettingsGroup[] = [
useSettingStore.getState().encryptBackups
)
useSettingStore.getState().toggleEncryptBackups();
if (await verifyAccount()) await createBackup();
const verified =
useSettingStore.getState().encryptBackups ||
(await verifyAccount());
if (verified) await createBackup();
},
variant: "secondary"
}
Expand Down Expand Up @@ -92,10 +95,15 @@ export const BackupExportSettings: SettingsGroup[] = [
],
selectedOption: () =>
useSettingStore.getState().backupReminderOffset.toString(),
onSelectionChanged: (value) =>
useSettingStore
.getState()
.setBackupReminderOffset(parseInt(value))
onSelectionChanged: async (value) => {
const verified =
useSettingStore.getState().encryptBackups ||
(await verifyAccount());
if (verified)
useSettingStore
.getState()
.setBackupReminderOffset(parseInt(value));
}
}
]
},
Expand All @@ -114,7 +122,12 @@ export const BackupExportSettings: SettingsGroup[] = [
isToggled: () =>
!!useUserStore.getState().isLoggedIn &&
useSettingStore.getState().encryptBackups,
toggle: () => useSettingStore.getState().toggleEncryptBackups()
toggle: async () => {
const verified =
!useSettingStore.getState().encryptBackups ||
(await verifyAccount());
if (verified) useSettingStore.getState().toggleEncryptBackups();
}
}
]
},
Expand All @@ -128,6 +141,11 @@ export const BackupExportSettings: SettingsGroup[] = [
type: "button",
title: "Select directory",
action: async () => {
const verified =
useSettingStore.getState().encryptBackups ||
(await verifyAccount());
if (!verified) return;

const backupStorageLocation =
useSettingStore.getState().backupStorageLocation ||
PATHS.backupsDirectory;
Expand Down Expand Up @@ -167,11 +185,11 @@ export const BackupExportSettings: SettingsGroup[] = [
selectedOption: () => "-",
onSelectionChanged: async (value) => {
if (!db.notes || value === "-") return;

await exportNotes(
value as "txt" | "md" | "html",
db.notes.all.map((n) => n.id)
);
if (await verifyAccount())
await exportNotes(
value as "txt" | "md" | "html",
db.notes.all.map((n) => n.id)
);
}
}
]
Expand Down

0 comments on commit 8c1629f

Please sign in to comment.