feat(captcha): trying to solve captcha issues

-
pull/1/head
TBS093A 2025-05-12 09:49:23 +02:00
parent de0d2c4ca4
commit 043dd5ce3d
2 changed files with 25 additions and 21 deletions

View File

@ -4,38 +4,40 @@ import { content_pl } from "../content/kamil"
import { content_en } from "../content/kamil"
import ReCAPTCHA from "react-google-recaptcha"
const RECAPTCHA_SITE_KEY = process.env.GATSBY_RECAPTCHA_SITE_KEY || "YOUR_RECAPTCHA_SITE_KEY"
// Klucz strony reCAPTCHA
const RECAPTCHA_SITE_KEY = process.env.GATSBY_RECAPTCHA_SITE_KEY || "YOUR_RECAPTCHA_SITE_KEY";
// Komponent obsługujący reCAPTCHA
const CaptchaWrapper = ({ onVerified }) => {
const [error, setError] = React.useState(null);
const isMounted = React.useRef(true);
const recaptchaRef = React.useRef(null);
React.useEffect(() => {
return () => {
isMounted.current = false;
};
}, []);
const handleCaptchaChange = (value) => {
if (isMounted.current && value) {
const handleCaptchaChange = () => {
try {
const token = recaptchaRef.current.getValue();
if (token) {
onVerified(true);
setError(null);
}
};
const handleCaptchaError = () => {
if (isMounted.current) {
setError('Wystąpił błąd podczas weryfikacji CAPTCHA');
onVerified(false);
} catch (err) {
console.error("reCAPTCHA error:", err);
setError("Wystąpił błąd podczas weryfikacji. Spróbuj ponownie.");
}
};
return (
<div className="captcha-container">
<ReCAPTCHA
ref={recaptchaRef}
sitekey={RECAPTCHA_SITE_KEY}
onChange={handleCaptchaChange}
onError={handleCaptchaError}
onErrored={() => setError("Wystąpił błąd podczas weryfikacji. Spróbuj ponownie.")}
onExpired={() => {
if (recaptchaRef.current) {
recaptchaRef.current.reset();
}
}}
hl="pl"
/>
{error && (
<div className="error-message" role="alert">

View File

@ -212,7 +212,9 @@ body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 20px 0;
padding: 10px;
.error-message {
color: #ff4444;