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.
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>
<body>
<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 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 (
<div className="App">
<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 = () => {
return (
<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>
)
}