From 9babb94e078f5a938445691563b756f20a15c20f Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Fri, 1 May 2026 23:32:25 +0300 Subject: [PATCH] fix(auth): add pexsecBot for Telegram login on app.pezkuwichain.io - pex.mom uses @PexMomBOT (8690398980) - app.pezkuwichain.io uses @pexsecBot (8754021997) - Edge function selects token based on bot_id from request --- web/src/pages/Login.tsx | 4 ++-- web/supabase/functions/telegram-auth/index.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/web/src/pages/Login.tsx b/web/src/pages/Login.tsx index f3248e8c..84f556ea 100644 --- a/web/src/pages/Login.tsx +++ b/web/src/pages/Login.tsx @@ -163,7 +163,7 @@ const Login: React.FC = () => { setError(''); setLoading(true); - const BOT_ID = '8690398980'; + const BOT_ID = window.location.hostname === 'pex.mom' ? '8690398980' : '8754021997'; const origin = window.location.origin; const popup = window.open( `https://oauth.telegram.org/auth?bot_id=${BOT_ID}&origin=${encodeURIComponent(origin)}&embed=1&request_access=write`, @@ -196,7 +196,7 @@ const Login: React.FC = () => { 'apikey': supabaseKey, 'Authorization': `Bearer ${supabaseKey}`, }, - body: JSON.stringify(tgData), + body: JSON.stringify({ ...tgData, bot_id: BOT_ID }), }); const json = await res.json(); diff --git a/web/supabase/functions/telegram-auth/index.ts b/web/supabase/functions/telegram-auth/index.ts index 286befc7..bce29995 100644 --- a/web/supabase/functions/telegram-auth/index.ts +++ b/web/supabase/functions/telegram-auth/index.ts @@ -42,11 +42,13 @@ Deno.serve(async (req) => { } try { - const botToken = Deno.env.get('TELEGRAM_BOT_TOKEN_PEZMOM') - if (!botToken) throw new Error('TELEGRAM_BOT_TOKEN_PEZMOM not configured') - const body = await req.json() - const { id, first_name, last_name, username, photo_url, auth_date, hash } = body + const { id, first_name, last_name, username, photo_url, auth_date, hash, bot_id } = body + + const botToken = bot_id === '8690398980' + ? Deno.env.get('TELEGRAM_BOT_TOKEN_PEZMOM') + : Deno.env.get('TELEGRAM_BOT_TOKEN_PEXSEC') + if (!botToken) throw new Error('Bot token not configured for bot_id: ' + bot_id) if (!id || !hash || !auth_date) { return new Response(JSON.stringify({ error: 'Missing required fields' }), {