Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/frontend/src/app/(platform)/reset-password/page.tsx (TypeScript)

Code before:
  const [isLoading, setIsLoading] = useState(false);
  const [feedback, setFeedback] = useState<string | null>(null);
  const [isError, setIsError] = useState(false);
  const [disabled, setDisabled] = useState(false);
  const [sendEmailCaptchaKey, setSendEmailCaptchaKey] = useState(0);
  const [changePasswordCaptchaKey, setChangePasswordCaptchaKey] = useState(0);

  const sendEmailTurnstile = useTurnstile({
    action: "reset_password",
    autoVerify: false,
    resetOnError: true,
  });

  const changePasswordTurnstile = useTurnstile({
    action: "change_password",
    autoVerify: false,
    resetOnError: true,
  });

  const sendEmailForm = useForm<z.infer<typeof sendEmailFormSchema>>({
    resolver: zodResolver(sendEmailFormSchema),
    defaultValues: {
      email: "",
    },
  });

  const changePasswordForm = useForm<z.infer<typeof changePasswordFormSchema>>({
    resolver: zodResolver(changePasswordFormSchema),
    defaultValues: {
      password: "",
      confirmPassword: "",
    },
  });

  const resetSendEmailCaptcha = useCallback(() => {
    setSendEmailCaptchaKey((k) => k + 1);
    sendEmailTurnstile.reset();
  }, [sendEmailTurnstile]);

  const resetChangePasswordCaptcha = useCallback(() => {
    setChangePasswordCaptchaKey((k) => k + 1);
    changePasswordTurnstile.reset();
  }, [changePasswordTurnstile]);

  const onSendEmail = useCallback(
    async (data: z.infer<typeof sendEmailFormSchema>) => {
      setIsLoading(true);
      setFeedback(null);

      if (!(await sendEmailForm.trigger())) {
        setIsLoading(false);

Review comment (bug):
This is to be explicit: it took me a long time to figure out the issue because the Supabase Client SDK (which was handling the code exchange for us) was failing silently due to being unable to access the session 💆🏽‍♂️ 

Code after:
export default function ResetPasswordPage() {
  const { supabase, user, isUserLoading } = useSupabase();
  const { toast } = useToast();
  const searchParams = useSearchParams();
  const router = useRouter();
  const [isLoading, setIsLoading] = useState(false);
  const [feedback, setFeedback] = useState<string | null>(null);
  const [isError, setIsError] = useState(false);
  const [disabled, setDisabled] = useState(false);
  const [sendEmailCaptchaKey, setSendEmailCaptchaKey] = useState(0);
  const [changePasswordCaptchaKey, setChangePasswordCaptchaKey] = useState(0);

  useEffect(() => {
    const error = searchParams.get("error");
    if (error) {
      toast({
        title: "Password Reset Failed",
        description: error,
        variant: "destructive",
      });

      const newUrl = new URL(window.location.href);
      newUrl.searchParams.delete("error");
      router.replace(newUrl.pathname + newUrl.search);
    }
  }, [searchParams, toast, router]);

  const sendEmailTurnstile = useTurnstile({
    action: "reset_password",
    autoVerify: false,
    resetOnError: true,
  });

  const changePasswordTurnstile = useTurnstile({
    action: "change_password",
    autoVerify: false,
    resetOnError: true,
  });

  const sendEmailForm = useForm<z.infer<typeof sendEmailFormSchema>>({
    resolver: zodResolver(sendEmailFormSchema),
    defaultValues: {
      email: "",
    },
  });

  const changePasswordForm = useForm<z.infer<typeof changePasswordFormSchema>>({
    resolver: zodResolver(changePasswordFormSchema),
    defaultValues: {
      password: "",
      confirmPassword: "",