Locazia: add not-working auth token request by webapp

This commit is contained in:
user 2024-02-22 19:49:21 +03:00
parent 034f47b36d
commit 2552bd842d
4 changed files with 40 additions and 4 deletions

View File

@ -24,7 +24,8 @@
work correctly both with client-side routing and a non-root public URL. 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`. Learn how to configure a non-root public URL by running `npm run build`.
--> -->
<title>React App</title> <title>MY</title>
<script src="https://telegram.org/js/telegram-web-app.js"></script>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>

View File

@ -1,11 +1,40 @@
import { useEffect } from 'react'; import {useEffect, useState} from 'react';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import Blank from './pages/Blank'; import Blank from './pages/Blank';
import { apiEndpoint } from "./constantsGlob";
import UploadContentPage from './pages/UploadContentPage'; import UploadContentPage from './pages/UploadContentPage';
import './index.css'; import './index.css';
function App() { 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 ( return (
<div className="App"> <div className="App">
<Router> <Router>

6
src/constantsGlob.js Normal file
View File

@ -0,0 +1,6 @@
const apiEndpoint: string = process.env.APP_API_ENDPOINT || 'http://192.168.0.170:13807/api/v1';
export {
apiEndpoint
};

View File

@ -2,7 +2,7 @@
const Blank = () => { const Blank = () => {
return ( return (
<div className="text-center"> <div className="text-center">
<p className="text-2xl text-gray-800 mono-font">Not found</p> <p className="text-2xl text-gray-800 mono-font">Web2 Client: Page not found</p>
</div> </div>
) )
} }