From a08f742237be9550b017b12d8b58ff1bfefcd9a9 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 24 Feb 2024 12:54:55 +0300 Subject: [PATCH] dev@locazia: add get /account --- src/App.tsx | 47 +++++++++++++++++++++++++++++++++----------- src/constantsGlob.js | 4 +++- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 99f623b..49ce7ed 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -21,20 +21,45 @@ function App() { "twa_data": window.Telegram.WebApp.initData }), }) - .then(response => { - if (!response.ok) { - throw new Error('Network response was not ok'); + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + if (data["auth_v1_token"] === undefined) { + window.location.href = "/unauthorized"; + return; + } + setApiToken(data["auth_v1_token"]); + }) + .catch(error => { + console.error('There was a problem with your fetch operation:', error); + }); + + fetch(`${apiEndpoint}/account`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Authorization': apiToken, } - return response.json(); }) - .then(data => { - console.log(data); - }) - .catch(error => { - console.error('There was a problem with your fetch operation:', error); - }); + .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"); + console.log("Telegram WebApp not found"); + window.location.href = "/unauthorized"; } }, []); return ( diff --git a/src/constantsGlob.js b/src/constantsGlob.js index aa545aa..116b917 100644 --- a/src/constantsGlob.js +++ b/src/constantsGlob.js @@ -1,5 +1,7 @@ -const apiEndpoint: string = process.env.REACT_APP_API_ENDPOINT || 'http://192.168.0.170:13807/api/v1'; +console.log('process.env.REACT_APP_API_ENDPOINT', process.env.REACT_APP_API_ENDPOINT); + +const apiEndpoint: string = 'https://music-gateway.letsw.app/api/v1'; export { apiEndpoint