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 { content_en } from "../content/kamil"
import ReCAPTCHA from "react-google-recaptcha" 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 CaptchaWrapper = ({ onVerified }) => {
const [error, setError] = React.useState(null); const [error, setError] = React.useState(null);
const isMounted = React.useRef(true); const recaptchaRef = React.useRef(null);
React.useEffect(() => { const handleCaptchaChange = () => {
return () => { try {
isMounted.current = false; const token = recaptchaRef.current.getValue();
}; if (token) {
}, []);
const handleCaptchaChange = (value) => {
if (isMounted.current && value) {
onVerified(true); onVerified(true);
setError(null); setError(null);
} }
}; } catch (err) {
console.error("reCAPTCHA error:", err);
const handleCaptchaError = () => { setError("Wystąpił błąd podczas weryfikacji. Spróbuj ponownie.");
if (isMounted.current) {
setError('Wystąpił błąd podczas weryfikacji CAPTCHA');
onVerified(false);
} }
}; };
return ( return (
<div className="captcha-container"> <div className="captcha-container">
<ReCAPTCHA <ReCAPTCHA
ref={recaptchaRef}
sitekey={RECAPTCHA_SITE_KEY} sitekey={RECAPTCHA_SITE_KEY}
onChange={handleCaptchaChange} 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 && ( {error && (
<div className="error-message" role="alert"> <div className="error-message" role="alert">

View File

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