mirror of
https://github.com/yawaflua/LuckyDiamond.git
synced 2026-02-05 10:44:11 +02:00
add auth connection with backend part
This commit is contained in:
@@ -1,41 +1,49 @@
|
||||
import { BackendApiUrl } from '@/properties/Сonfig.js';
|
||||
|
||||
|
||||
export async function Post(url = "", data = {}) {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
redirect: "follow"
|
||||
});
|
||||
|
||||
// Default options are marked with *
|
||||
// try {
|
||||
// const response = await fetch(url, {
|
||||
// method: "POST",
|
||||
// headers: {
|
||||
// "Content-Type": "application/json",
|
||||
// },
|
||||
// redirect: "follow",
|
||||
// referrerPolicy: "no-referrer",
|
||||
// body: JSON.stringify(data),
|
||||
// });
|
||||
// if (!response.ok) {
|
||||
// console.log("Fetch error:", response.status);
|
||||
// }
|
||||
// return await response.json();
|
||||
// } catch (error) {
|
||||
// console.log("Fetch error:", error);
|
||||
// }
|
||||
if (!response.ok) {
|
||||
console.log("Fetch error:", response.status);
|
||||
}
|
||||
|
||||
var myHeaders = new Headers();
|
||||
myHeaders.append("Content-Type", "application/json");
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.log("Fetch error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
var raw = JSON.stringify(data);
|
||||
export async function GetCurrentMoney(authToken) {
|
||||
|
||||
try {
|
||||
const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'AuthToken': authToken,
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log(data); // Здесь вы можете обработать полученные данные
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('There was a problem with the fetch operation:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var requestOptions = {
|
||||
method: 'POST',
|
||||
headers: myHeaders,
|
||||
body: raw,
|
||||
redirect: 'follow'
|
||||
};
|
||||
|
||||
fetch(url, requestOptions)
|
||||
.then(response => response.text())
|
||||
.then(result => console.log(result))
|
||||
.catch(error => console.log('error', error));
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user