fix: prevent React StrictMode double execution in Verify
Added hasVerified flag to prevent useEffect from running twice in React 18 StrictMode (development mode). This was causing: 1. First call: 200 OK - verification successful 2. Second call: 400 Bad Request - already verified 3. Error shown to user despite successful verification The fix ensures verify() only runs once per component mount. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ca9112ebc0
commit
e62b05c224
|
|
@ -14,15 +14,17 @@ export default function Verify() {
|
||||||
const [email, setEmail] = useState('')
|
const [email, setEmail] = useState('')
|
||||||
const [resending, setResending] = useState(false)
|
const [resending, setResending] = useState(false)
|
||||||
const [resendSuccess, setResendSuccess] = useState(false)
|
const [resendSuccess, setResendSuccess] = useState(false)
|
||||||
|
const [hasVerified, setHasVerified] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (hasVerified) return // Prevent React StrictMode double execution
|
||||||
|
if (!token) {
|
||||||
|
setStatus('error')
|
||||||
|
setError('Kein Verifikations-Token gefunden')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setHasVerified(true)
|
||||||
const verify = async () => {
|
const verify = async () => {
|
||||||
if (!token) {
|
|
||||||
setStatus('error')
|
|
||||||
setError('Kein Verifikations-Token gefunden')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await api.verifyEmail(token)
|
const result = await api.verifyEmail(token)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user