diff --git a/src/app/actions/captcha.ts b/src/app/actions/captcha.ts deleted file mode 100644 index ea497dd..0000000 --- a/src/app/actions/captcha.ts +++ /dev/null @@ -1,14 +0,0 @@ -'use server' - -import { generateCaptcha, signCaptcha } from "@/lib/captcha" - -export interface CaptchaResponse { - image: string - hash: string -} - -export async function getNewCaptcha(): Promise { - const { text, data } = generateCaptcha() - const hash = signCaptcha(text) - return { image: data, hash } -} diff --git a/src/components/ui/captcha.tsx b/src/components/ui/captcha.tsx deleted file mode 100644 index e89cf68..0000000 --- a/src/components/ui/captcha.tsx +++ /dev/null @@ -1,90 +0,0 @@ -'use client' - -import { useState, useEffect, forwardRef, useImperativeHandle, useCallback } from 'react' -import { getNewCaptcha, CaptchaResponse } from '@/app/actions/captcha' -import { Button } from "@/components/ui/button" -import { Input } from "@/components/ui/input" -import { Label } from "@/components/ui/label" -import { Loader2, RefreshCw } from "lucide-react" - -interface CaptchaProps { - onVerify: (hash: string, value: string) => void -} - -export interface CaptchaRef { - reset: () => void -} - -export const Captcha = forwardRef(({ onVerify }, ref) => { - const [captcha, setCaptcha] = useState(null) - const [input, setInput] = useState("") - const [loading, setLoading] = useState(true) - - const fetchCaptcha = useCallback(async () => { - setLoading(true) - try { - const data = await getNewCaptcha() - setCaptcha(data) - setInput("") - onVerify(data.hash, "") // Reset parent state - } catch (error) { - console.error("Captcha fetch failed", error) - } finally { - setLoading(false) - } - }, [onVerify]) - - useEffect(() => { - fetchCaptcha() - }, [fetchCaptcha]) - - useImperativeHandle(ref, () => ({ - reset: fetchCaptcha - })) - - const handleChange = (e: React.ChangeEvent) => { - const value = e.target.value - setInput(value) - if (captcha) { - onVerify(captcha.hash, value) - } - } - - return ( -
- -
-
-
- {loading && ( -
- -
- )} -
- -
- -
- ) -}) - -Captcha.displayName = "Captcha"