diff --git a/App/app/(portal)/profile/actions.ts b/App/app/(portal)/profile/actions.ts index 46ca699..707f07a 100644 --- a/App/app/(portal)/profile/actions.ts +++ b/App/app/(portal)/profile/actions.ts @@ -12,7 +12,7 @@ type Result = { ok: true } | { error: string }; // ── Change password ─────────────────────────────────────────────────────────── const changePasswordSchema = z.object({ - currentPassword: z.string().min(1, "Current password is required"), + currentPassword: z.string().optional(), newPassword: z.string().min(8, "New password must be at least 8 characters"), }); @@ -31,10 +31,12 @@ export async function changePassword(formData: FormData): Promise { select: { passwordHash: true }, }); if (!user) return { error: "User not found" }; - if (!user.passwordHash) return { error: "Password change is not available for accounts that sign in via Microsoft 365." }; - const valid = await bcrypt.compare(parsed.data.currentPassword, user.passwordHash); - if (!valid) return { error: "Current password is incorrect" }; + if (user.passwordHash) { + if (!parsed.data.currentPassword) return { error: "Current password is required." }; + const valid = await bcrypt.compare(parsed.data.currentPassword, user.passwordHash); + if (!valid) return { error: "Current password is incorrect." }; + } const newHash = await bcrypt.hash(parsed.data.newPassword, 12); await db.user.update({ diff --git a/App/app/(portal)/profile/change-password-form.tsx b/App/app/(portal)/profile/change-password-form.tsx index f15dd52..a57c394 100644 --- a/App/app/(portal)/profile/change-password-form.tsx +++ b/App/app/(portal)/profile/change-password-form.tsx @@ -43,7 +43,6 @@ export function ChangePasswordForm() {