dockerfile update and login
This commit is contained in:
@@ -31,8 +31,13 @@ export function AuthClient({ dict, lang }: AuthClientProps) {
|
||||
>("processing");
|
||||
const [logs, setLogs] = useState<string[]>([]);
|
||||
const tgContainerRef = useRef<HTMLDivElement>(null);
|
||||
const initialized = useRef(false);
|
||||
const widgetInjected = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (initialized.current) return;
|
||||
initialized.current = true;
|
||||
|
||||
const authenticate = async () => {
|
||||
setLogs((prev) => [...prev, `> ${dict.processing}`]);
|
||||
|
||||
@@ -42,14 +47,23 @@ export function AuthClient({ dict, lang }: AuthClientProps) {
|
||||
const hash = window.location.hash;
|
||||
let token = localStorage.getItem("nrxp_token");
|
||||
|
||||
// Логика получения токена из хеша (переход из Telegram бота)
|
||||
if (hash.includes("token=")) {
|
||||
// Логика получения токена из query parameters или хеша
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const queryToken = searchParams.get("token");
|
||||
|
||||
if (queryToken) {
|
||||
token = queryToken;
|
||||
searchParams.delete("token");
|
||||
const newSearch = searchParams.toString();
|
||||
const newUrl = window.location.pathname + (newSearch ? `?${newSearch}` : "") + window.location.hash;
|
||||
window.history.replaceState(null, "", newUrl);
|
||||
} else if (hash.includes("token=")) {
|
||||
const params = new URLSearchParams(hash.replace("#", "?"));
|
||||
const urlToken = params.get("token");
|
||||
if (urlToken) {
|
||||
token = urlToken;
|
||||
// Безопасно очищаем URL от токена
|
||||
window.history.replaceState(null, "", window.location.pathname);
|
||||
// Безопасно очищаем URL от токена, сохраняя search params
|
||||
window.history.replaceState(null, "", window.location.pathname + window.location.search);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,11 +146,12 @@ export function AuthClient({ dict, lang }: AuthClientProps) {
|
||||
if (
|
||||
status === "awaiting" &&
|
||||
tgContainerRef.current &&
|
||||
!document.getElementById("tg-widget")
|
||||
!widgetInjected.current
|
||||
) {
|
||||
widgetInjected.current = true;
|
||||
const script = document.createElement("script");
|
||||
script.id = "tg-widget";
|
||||
script.src = "https://telegram.org/js/telegram-widget.js?22";
|
||||
script.async = true;
|
||||
script.setAttribute(
|
||||
"data-telegram-login",
|
||||
process.env.NEXT_PUBLIC_BOT_USERNAME || "ntrnr_vpn_bot",
|
||||
@@ -240,7 +255,7 @@ export function AuthClient({ dict, lang }: AuthClientProps) {
|
||||
</p>
|
||||
{/* При ошибке даем ссылку на телеграм бота для авторизации */}
|
||||
<CyberButton
|
||||
href="https://t.me/ntrnr_vpn_bot"
|
||||
href={`https://t.me/${process.env.NEXT_PUBLIC_BOT_USERNAME || "ntrnr_vpn_bot"}`}
|
||||
variant="primary"
|
||||
className="w-full sm:w-auto"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user