From 71205b67dc6054cb207949ed88cd93dc60990cb7 Mon Sep 17 00:00:00 2001
From: Morfixx <63129378+nahSystemu@users.noreply.github.com>
Date: Mon, 11 May 2026 05:40:59 -0700
Subject: [PATCH] fix: unable to change password when using magic link (#484)
* fix: fixed password not resetting & added password prompt with save guards
* fix: migrated to using setPassword
---
apps/web/src/components/Dashboard.tsx | 40 ++++++-
.../src/views/settings/AccountSettings.tsx | 10 +-
.../components/ChangePasswordConfirmation.tsx | 108 ++++++++++++------
packages/api/src/routers/user.ts | 42 +++++++
packages/api/src/trpc.ts | 5 +
packages/db/src/repository/user.repo.ts | 75 ++++++++----
6 files changed, 218 insertions(+), 62 deletions(-)
diff --git a/apps/web/src/components/Dashboard.tsx b/apps/web/src/components/Dashboard.tsx
index ecff8acb..c6f2eac2 100644
--- a/apps/web/src/components/Dashboard.tsx
+++ b/apps/web/src/components/Dashboard.tsx
@@ -8,6 +8,7 @@ import {
TbLayoutSidebarRightCollapse,
TbLayoutSidebarRightExpand,
} from "react-icons/tb";
+import { t } from "@lingui/core/macro";
import { authClient } from "@kan/auth/client";
@@ -15,7 +16,10 @@ import { useClickOutside } from "~/hooks/useClickOutside";
import { useModal } from "~/providers/modal";
import { useWorkspace, WorkspaceProvider } from "~/providers/workspace";
import { api } from "~/utils/api";
+import Button from "./Button";
+import Modal from "./modal";
import SideNavigation from "./SideNavigation";
+import { ChangePasswordFormConfirmation } from "~/views/settings/components/ChangePasswordConfirmation";
interface DashboardProps {
children: React.ReactNode;
@@ -43,7 +47,7 @@ export default function Dashboard({
hasRightPanel = false,
}: DashboardProps) {
const { resolvedTheme } = useTheme();
- const { openModal } = useModal();
+ const { openModal, closeModal, modalContentType } = useModal();
const { availableWorkspaces, hasLoaded } = useWorkspace();
const router = useRouter();
@@ -109,6 +113,24 @@ export default function Dashboard({
}
}, [hasLoaded, availableWorkspaces.length, openModal, router]);
+ useEffect(() => {
+ const isCredentialsEnabled =
+ env("NEXT_PUBLIC_ALLOW_CREDENTIALS")?.toLowerCase() === "true";
+
+ if (
+ !userLoading &&
+ user &&
+ isCredentialsEnabled &&
+ user.hasMagicLinkAccount &&
+ !user.hasPassword &&
+ typeof window !== "undefined" &&
+ !sessionStorage.getItem("set_password_prompted")
+ ) {
+ sessionStorage.setItem("set_password_prompted", "1");
+ openModal("SET_PASSWORD_PROMPT");
+ }
+ }, [user, userLoading, openModal]);
+
const isDarkMode = resolvedTheme === "dark";
return (
@@ -203,6 +225,22 @@ export default function Dashboard({
+
+
+ {t`Your account already has a password. You can change it from your account settings.`}
+ {t`Password already set`}
+
- {t`You are about to change your password.`} + {data?.hasPassword + ? t`You are about to change your password.` + : t`Set a password to enable password-based login.`}
- {t`Enter your current password and choose a new secure password.`} + {hasPassword + ? t`Enter your current password and choose a new secure password.` + : t`You signed in without a password. Set a password to enable password-based login.`}