MCPcopy
hub / github.com/fastapi/full-stack-fastapi-template / ResetPassword

Function ResetPassword

frontend/src/routes/reset-password.tsx:69–166  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67})
68
69function ResetPassword() {
70 const { token } = Route.useSearch()
71 const { showSuccessToast, showErrorToast } = useCustomToast()
72 const navigate = useNavigate()
73
74 const form = useForm<FormData>({
75 resolver: zodResolver(formSchema),
76 mode: "onBlur",
77 criteriaMode: "all",
78 defaultValues: {
79 new_password: "",
80 confirm_password: "",
81 },
82 })
83
84 const mutation = useMutation({
85 mutationFn: (data: { new_password: string; token: string }) =>
86 LoginService.resetPassword({ requestBody: data }),
87 onSuccess: () => {
88 showSuccessToast("Password updated successfully")
89 form.reset()
90 navigate({ to: "/login" })
91 },
92 onError: handleError.bind(showErrorToast),
93 })
94
95 const onSubmit = (data: FormData) => {
96 mutation.mutate({ new_password: data.new_password, token })
97 }
98
99 return (
100 <AuthLayout>
101 <Form {...form}>
102 <form
103 onSubmit={form.handleSubmit(onSubmit)}
104 className="flex flex-col gap-6"
105 >
106 <div className="flex flex-col items-center gap-2 text-center">
107 <h1 className="text-2xl font-bold">Reset Password</h1>
108 </div>
109
110 <div className="grid gap-4">
111 <FormField
112 control={form.control}
113 name="new_password"
114 render={({ field }) => (
115 <FormItem>
116 <FormLabel>New Password</FormLabel>
117 <FormControl>
118 <PasswordInput
119 data-testid="new-password-input"
120 placeholder="New Password"
121 {...field}
122 />
123 </FormControl>
124 <FormMessage />
125 </FormItem>
126 )}

Callers

nothing calls this directly

Calls 3

useCustomToastFunction · 0.85
showSuccessToastFunction · 0.85
resetPasswordMethod · 0.80

Tested by

no test coverage detected