const tg = window.Telegram.WebApp;
tg.ready();
const initData = tg.initData || "";
// Check if there is any init data
if (initData) {
// Encode the initdata using Base64 to create an authorization token
const authToken = btoa(initData);
// Function to fetch data from an API
async function fetchData() {
try {
const response = await fetch("https://api-endpoint.com", {
method: "GET",
// Set the Authorization header with the Bearer token
headers: {
"Authorization": `Bearer ${authToken}`,
},
});
if (response.ok) {
const data = await response.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.");
}
-
Notifications
You must be signed in to change notification settings - Fork 0
Telegram Mini App Authenticate with initdata | Flask backend
License
cnncodex/TMA-Auth-Backend
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Telegram Mini App Authenticate with initdata | Flask backend
Topics
Resources
License
Stars
Watchers
Forks
Releases
No releases published