diff --git a/apps/web/src/common/dialog-controller.tsx b/apps/web/src/common/dialog-controller.tsx index 58012443c..9777ac536 100644 --- a/apps/web/src/common/dialog-controller.tsx +++ b/apps/web/src/common/dialog-controller.tsx @@ -430,7 +430,13 @@ function getDialogData(type: string) { export function showPasswordDialog( type: string, - validate: ({ password }: { password: string }) => boolean | Promise + validate: ({ + password + }: { + password?: string; + oldPassword?: string; + newPassword?: string; + }) => boolean | Promise ) { const { title, subtitle, positiveButtonText, checks } = getDialogData(type); return showDialog("PasswordDialog", (Dialog, perform) => ( diff --git a/apps/web/src/dialogs/settings/auth-settings.ts b/apps/web/src/dialogs/settings/auth-settings.ts index 8a9ec7d29..7acab46a7 100644 --- a/apps/web/src/dialogs/settings/auth-settings.ts +++ b/apps/web/src/dialogs/settings/auth-settings.ts @@ -22,8 +22,11 @@ import { useStore as useUserStore } from "../../stores/user-store"; import { verifyAccount } from "../../common"; import { show2FARecoveryCodesDialog, - showMultifactorDialog + showMultifactorDialog, + showPasswordDialog } from "../../common/dialog-controller"; +import { db } from "../../common/db"; +import { showToast } from "../../utils/toast"; export const AuthenticationSettings: SettingsGroup[] = [ { @@ -41,7 +44,21 @@ export const AuthenticationSettings: SettingsGroup[] = [ type: "button", title: "Change password", variant: "secondary", - action: () => {} + action: async () => { + const result = await showPasswordDialog( + "change_account_password", + async (data) => { + await db.user?.clearSessions(); + return ( + db.user?.changePassword( + data.oldPassword, + data.newPassword + ) || false + ); + } + ); + if (result) showToast("success", "Account password changed!"); + } } ] }