33
44"use client" ;
55
6- import { useState } from "react" ;
6+ import { useEffect , useState } from "react" ;
77import { useFormContext } from "react-hook-form" ;
88import type { OryNodeInputProps } from "@ory/elements-react" ;
99import { Label } from "@/components/ui/label" ;
10- import {
11- CONFIRM_PASSWORD_LABEL ,
12- PasswordField ,
13- usePasswordMismatch ,
14- } from "../PasswordField" ;
10+ import { usePasswordMismatch } from "@/hooks/usePasswordMismatch" ;
11+ import { CONFIRM_PASSWORD_LABEL , PasswordField } from "../PasswordField" ;
1512import { OryInput } from "./OryInput" ;
1613
1714export function OryRegistrationInput ( props : OryNodeInputProps ) {
1815 const { node, attributes, onClick } = props ;
19- const { register } = useFormContext ( ) ;
16+ const {
17+ register,
18+ resetField,
19+ formState : { isSubmitting } ,
20+ } = useFormContext ( ) ;
2021 const mismatch = usePasswordMismatch ( ) ;
2122 const [ confirmTouched , setConfirmTouched ] = useState ( false ) ;
2223 const { value, name, autocomplete, maxlength, ...rest } = attributes ;
2324
25+ useEffect ( ( ) => {
26+ if ( isSubmitting ) {
27+ resetField ( "confirmPassword" ) ;
28+ setConfirmTouched ( false ) ;
29+ }
30+ } , [ isSubmitting , resetField ] ) ;
31+
2432 // Only the password field gets the extra confirmation field. Every other
2533 // node (email, name, hidden, csrf, …) renders exactly like the standard
2634 // input, so we delegate to OryInput rather than duplicating that logic.
@@ -30,7 +38,7 @@ export function OryRegistrationInput(props: OryNodeInputProps) {
3038
3139 // Show the mismatch error only once the confirm field has been touched, but
3240 // keep it watch-driven so it clears live as soon as the values match.
33- const showMismatch = confirmTouched && mismatch ;
41+ const showMismatch = ! isSubmitting && confirmTouched && mismatch ;
3442
3543 return (
3644 < div className = "flex flex-col gap-1" >
0 commit comments