Files
mechanic-pwa/driver-pwa/frontend/src/pages/TgWaitPage.tsx
T
tremble7681andclaude-flow d2cd7632a5 fix(pwa): keep PWA alive during TG login (anchor opens Telegram, app polls on /tg-wait)
window.location.href=deep_link navigated the whole PWA to t.me, destroying the
/tg-wait polling screen -> the authenticated token was never fetched. Prefetch
the pairing session and open Telegram via an <a href> (OS app-switch, PWA stays
mounted polling); add an Open-Telegram fallback link on the wait screen.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-06-19 23:44:57 +10:00

44 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { usePairPoll } from "@/hooks/usePairPoll";
import { Spinner } from "@/components/Spinner";
export function TgWaitPage() {
const nav = useNavigate();
const pairSession = sessionStorage.getItem("pp-pair-session");
const deepLink = sessionStorage.getItem("pp-pair-deeplink");
const { status } = usePairPoll(pairSession);
useEffect(() => {
if (!pairSession) { nav("/login", { replace: true }); }
}, [pairSession, nav]);
useEffect(() => {
if (status === "authenticated") {
sessionStorage.removeItem("pp-pair-session");
sessionStorage.removeItem("pp-pair-deeplink");
nav("/", { replace: true });
}
if (status === "expired") {
sessionStorage.removeItem("pp-pair-session");
sessionStorage.removeItem("pp-pair-deeplink");
nav("/login", { replace: true, state: { expired: true } });
}
}, [status, nav]);
return (
<div className="pt-16 text-center">
<h1 className="text-xl font-extrabold mb-2">Премиум Водитель</h1>
<p className="text-muted text-sm mb-6">
В Telegram нажмите «Поделиться номером для входа», затем вернитесь сюда вход произойдёт автоматически.
</p>
{deepLink && (
<a href={deepLink} target="_blank" rel="noopener noreferrer" className="btn-primary block text-center mb-6">
Открыть Telegram
</a>
)}
<Spinner />
</div>
);
}