feat: add soft ui auth page
This commit is contained in:
@@ -110,6 +110,8 @@ export default function ClaimForm() {
|
||||
const [tgDebug, setTgDebug] = useState<string>('');
|
||||
/** Дефолт = веб. Скин TG подставляется только при заходе через Telegram Mini App. */
|
||||
const [isTelegramMiniApp, setIsTelegramMiniApp] = useState(false);
|
||||
/** Заход через MAX Mini App. */
|
||||
const [isMaxMiniApp, setIsMaxMiniApp] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// 🔥 VERSION CHECK: Если видишь это в консоли - фронт обновился!
|
||||
@@ -182,6 +184,68 @@ export default function ClaimForm() {
|
||||
if (!webApp?.initData) {
|
||||
const tg = getTg();
|
||||
console.log('[TG] После ожидания', maxWaitMs, 'ms: Telegram=', !!tg, 'WebApp=', !!tg?.WebApp, 'initData=', !!tg?.WebApp?.initData, '→ пропускаем tg/auth');
|
||||
// Если Telegram не найден — пробуем MAX Mini App (window.WebApp от MAX Bridge)
|
||||
let maxWebApp = (window as any).WebApp;
|
||||
const maxWait = 4000;
|
||||
for (let t = 0; t < maxWait; t += 200) {
|
||||
await new Promise((r) => setTimeout(r, 200));
|
||||
maxWebApp = (window as any).WebApp;
|
||||
if (maxWebApp?.initData && maxWebApp.initData.length > 0) break;
|
||||
}
|
||||
if (maxWebApp?.initData && typeof maxWebApp.initData === 'string' && maxWebApp.initData.length > 0) {
|
||||
const hasHash = maxWebApp.initData.includes('hash=');
|
||||
console.log('[MAX] Обнаружен MAX WebApp, initData длина=', maxWebApp.initData.length, ', есть hash=', hasHash);
|
||||
setIsMaxMiniApp(true);
|
||||
try { maxWebApp.ready?.(); } catch (_) {}
|
||||
const existingToken = localStorage.getItem('session_token');
|
||||
if (existingToken) {
|
||||
console.log('[MAX] session_token уже есть → max/auth не вызываем');
|
||||
setTelegramAuthChecked(true);
|
||||
return;
|
||||
}
|
||||
setTgDebug('MAX: POST /api/v1/max/auth...');
|
||||
try {
|
||||
const maxRes = await fetch('/api/v1/max/auth', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ init_data: maxWebApp.initData }),
|
||||
});
|
||||
const maxData = await maxRes.json();
|
||||
if (maxData.need_contact) {
|
||||
setTgDebug('MAX: Нужен контакт — закрываем приложение');
|
||||
try { maxWebApp.close?.(); } catch (_) {}
|
||||
setTelegramAuthChecked(true);
|
||||
return;
|
||||
}
|
||||
if (maxRes.ok && maxData.success) {
|
||||
if (maxData.session_token) {
|
||||
localStorage.setItem('session_token', maxData.session_token);
|
||||
sessionIdRef.current = maxData.session_token;
|
||||
}
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
unified_id: maxData.unified_id,
|
||||
phone: maxData.phone,
|
||||
contact_id: maxData.contact_id,
|
||||
session_id: maxData.session_token,
|
||||
}));
|
||||
setIsPhoneVerified(true);
|
||||
if (maxData.has_drafts) {
|
||||
setShowDraftSelection(true);
|
||||
setHasDrafts(true);
|
||||
setCurrentStep(0);
|
||||
} else {
|
||||
setCurrentStep(1);
|
||||
}
|
||||
} else {
|
||||
console.error('[MAX] max/auth ответ', maxRes.status, maxData);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[MAX] Ошибка max/auth:', e);
|
||||
}
|
||||
setTelegramAuthChecked(true);
|
||||
return;
|
||||
}
|
||||
setTelegramAuthChecked(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user