fix: clear all cached auth state on Telegram MiniApp retry

When users hit 'Try Again' after auth failure, clear ALL cached state
(tokens, SDK launch params, initData, zustand persist, tg_user_id)
to prevent stale token loops. Applies to both Login and TelegramRedirect
retry handlers.
This commit is contained in:
Fringg
2026-03-22 07:24:45 +03:00
parent 1538879f97
commit 3e27472c8a
2 changed files with 19 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import { useAuthStore } from '../store/auth';
import { useShallow } from 'zustand/shallow';
import { brandingApi } from '../api/branding';
import { isInTelegramWebApp, getTelegramInitData } from '../hooks/useTelegramSDK';
import { tokenStorage } from '../utils/token';
// Validate redirect URL to prevent open redirect attacks
const getSafeRedirectUrl = (url: string | null): string => {
@@ -117,6 +118,14 @@ export default function TelegramRedirect() {
const newCount = retryCount + 1;
setRetryCount(newCount);
sessionStorage.setItem(RETRY_COUNT_KEY, String(newCount));
// Clear all cached auth state to prevent stale token/initData loops
tokenStorage.clearTokens();
sessionStorage.removeItem('tapps/launchParams');
sessionStorage.removeItem('telegram_init_data');
localStorage.removeItem('cabinet-auth');
localStorage.removeItem('tg_user_id');
setStatus('loading');
setErrorMessage('');
window.location.reload();