Add auth provider

This commit is contained in:
Hepatica
2023-11-25 21:56:01 +01:00
parent 041c54c4ac
commit 28b3846ec7
4 changed files with 75 additions and 42 deletions

View File

@@ -1,21 +1,41 @@
export async function Post(url = "", data = {}) {
// 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) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.log("Fetch error:", error);
throw error; // Re-throw the error so it can be caught by the calling function
}
// 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);
// }
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify(data);
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));
}