fix: clear consumed Telegram challenges after link changes

This commit is contained in:
2026-09-06 14:53:35 +03:00
parent 283bfe5990
commit 37fb7b0366
6 changed files with 43 additions and 12 deletions
+3 -2
View File
@@ -31,8 +31,8 @@ const TelegramPanel = ({isAdmin}) => {
const calistir = async (ad, fn, basari) => {
if(locked.current)return;locked.current=true;
setBusy(ad);setMesaj(null);
try {await fn();if(!alive.current)return;if(ad!=='load')await yenile();if(alive.current&&basari)setMesaj({tur:'ok',metin:basari});}
catch(e){if(alive.current)setMesaj({tur:'hata',metin:e.message});}
try {await fn();if(!alive.current)return;if(ad==='bagla'||ad==='sil')setChallenge(null);if(ad!=='load')await yenile();if(alive.current&&basari)setMesaj({tur:'ok',metin:basari});}
catch(e){if(alive.current){if(e.kod==='TELEGRAM_CHALLENGE_INVALID')setChallenge(null);setMesaj({tur:'hata',metin:e.message});}}
finally{locked.current=false;if(alive.current)setBusy(null);}
};
useEffect(()=>{alive.current=true;void calistir('load',yenile);return()=>{alive.current=false;};},[]);
@@ -95,6 +95,7 @@ const TelegramPanel = ({isAdmin}) => {
<li>Sonra buraya dönüp <strong>Doğrula</strong>'ya basın.</li>
</ol>
<button disabled={!!busy} className="border rounded px-3 py-2" onClick={()=>calistir('kod',async()=>{
setChallenge(null);
const data=await telegramKodOlustur();
if(typeof data.kod!=='string'||!/^[a-f0-9]{48}$/.test(data.kod)||!Number.isFinite(data.expiresAt))throw new Error('Bağlama kodu doğrulanamadı.');
if(alive.current)setChallenge(data);