Skip to content

Commit f01698c

Browse files
fix: Fix the forgot password form
1 parent 37ce6a4 commit f01698c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/app/(auth)/forgot-password/forgot-password.client.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useSessionStore } from "@/state/session";
2121
import { Captcha } from "@/components/captcha";
2222
import { forgotPasswordSchema } from "@/schemas/forgot-password.schema";
2323
import { useConfigStore } from "@/state/config";
24+
import { useEffect } from "react";
2425

2526
type ForgotPasswordSchema = z.infer<typeof forgotPasswordSchema>;
2627

@@ -33,6 +34,12 @@ export default function ForgotPasswordClientComponent() {
3334
resolver: zodResolver(forgotPasswordSchema),
3435
});
3536

37+
useEffect(() => {
38+
if (session?.user?.email) {
39+
form.setValue('email', session?.user?.email);
40+
}
41+
}, [form,session?.user?.email]);
42+
3643
const captchaToken = useWatch({ control: form.control, name: 'captchaToken' })
3744

3845
const { execute: sendResetLink, isSuccess } = useServerAction(forgotPasswordAction, {
@@ -50,7 +57,10 @@ export default function ForgotPasswordClientComponent() {
5057
});
5158

5259
const onSubmit = async (data: ForgotPasswordSchema) => {
53-
sendResetLink(data);
60+
sendResetLink({
61+
...data,
62+
email: data.email ?? session?.user?.email,
63+
});
5464
};
5565

5666
if (isSuccess) {

0 commit comments

Comments
 (0)