mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
web: add missing change password logic
This commit is contained in:
committed by
Abdullah Atta
parent
8c494642e4
commit
36a99cd64f
@@ -430,7 +430,13 @@ function getDialogData(type: string) {
|
||||
|
||||
export function showPasswordDialog(
|
||||
type: string,
|
||||
validate: ({ password }: { password: string }) => boolean | Promise<boolean>
|
||||
validate: ({
|
||||
password
|
||||
}: {
|
||||
password?: string;
|
||||
oldPassword?: string;
|
||||
newPassword?: string;
|
||||
}) => boolean | Promise<boolean>
|
||||
) {
|
||||
const { title, subtitle, positiveButtonText, checks } = getDialogData(type);
|
||||
return showDialog("PasswordDialog", (Dialog, perform) => (
|
||||
|
||||
@@ -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!");
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user