You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Telegram Mini App Authenticate with intidata | Flask backend
☘️ Frontend examples
consttg=window.Telegram.WebApp;tg.ready();constinitData=tg.initData||"";// Check if there is any init dataif(initData){// Encode the initdata using Base64 to create an authorization tokenconstauthToken=btoa(initData);// Function to fetch data from an APIasyncfunctionfetchData(){try{constresponse=awaitfetch("https://api-endpoint.com",{method: "GET",// Set the Authorization header with the Bearer tokenheaders: {"Authorization": `Bearer ${authToken}`,},});if(response.ok){constdata=awaitresponse.json();// console.log("Data fetched successfully:", data);}else{console.error("Failed to fetch data:",response.status,response.statusText);}}catch(error){console.error("Error fetching data:",error);}}fetchData();}else{console.log("No initdata available.");}