diff --git a/public/index.html b/public/index.html index aa069f2..e086a54 100644 --- a/public/index.html +++ b/public/index.html @@ -24,7 +24,8 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - React App + MY + diff --git a/src/App.tsx b/src/App.tsx index a522d91..2ca312b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,11 +1,40 @@ -import { useEffect } from 'react'; +import {useEffect, useState} from 'react'; import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; import Blank from './pages/Blank'; +import { apiEndpoint } from "./constantsGlob"; import UploadContentPage from './pages/UploadContentPage'; import './index.css'; function App() { - useEffect(() => {}, []); + const [apiToken, setApiToken] = useState(''); + + useEffect(() => { + if (window.Telegram && window.Telegram.WebApp) { + fetch(`${apiEndpoint}/auth.twa`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + "twa_data": window.Telegram.WebApp.initData + }), + }) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + console.log(data); + }) + .catch(error => { + console.error('There was a problem with your fetch operation:', error); + }); + } else { + console.log("Telegram WebApp not found"); + } + }, []); return (
diff --git a/src/constantsGlob.js b/src/constantsGlob.js new file mode 100644 index 0000000..4d4c38a --- /dev/null +++ b/src/constantsGlob.js @@ -0,0 +1,6 @@ + +const apiEndpoint: string = process.env.APP_API_ENDPOINT || 'http://192.168.0.170:13807/api/v1'; + +export { + apiEndpoint +}; diff --git a/src/pages/Blank.tsx b/src/pages/Blank.tsx index ac79ec9..dea7756 100644 --- a/src/pages/Blank.tsx +++ b/src/pages/Blank.tsx @@ -2,7 +2,7 @@ const Blank = () => { return (
-

Not found

+

Web2 Client: Page not found

) }