db changes, refactoring with axios
This commit is contained in:
@@ -3,6 +3,7 @@ import axios from "axios";
|
||||
const API = import.meta.env.APISTRING || "http://localhost:8080";
|
||||
|
||||
axios.defaults.withCredentials = true;
|
||||
axios.defaults.headers['Content-Type'] = 'application/json';
|
||||
|
||||
export const getBaseAPI = async () => {
|
||||
return fetch(API);
|
||||
@@ -30,11 +31,9 @@ export const checkCredientials = async () => {
|
||||
url: API + '/auth',
|
||||
});
|
||||
|
||||
const data = Promise.resolve(response.data);
|
||||
return data;
|
||||
return Promise.resolve(response.data);
|
||||
} catch (e: any) {
|
||||
throw e;
|
||||
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,29 +46,47 @@ export const attemptLogout = async () => {
|
||||
} catch (e: any) {
|
||||
throw e;
|
||||
}
|
||||
// const result = await fetch(API + 'auth/logout', { method: "DELETE" }).then(response => response.json());
|
||||
// return result;
|
||||
}
|
||||
|
||||
export const attemptRegister = async (data: IUser) => {
|
||||
const result = await fetch(API + 'auth/register/', {
|
||||
export const attemptRegister = async (body: IUser) => {
|
||||
try {
|
||||
const response = await axios({
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
}).then(response => response.json());
|
||||
|
||||
return result;
|
||||
url: API + '/auth/register',
|
||||
data: JSON.stringify(body)
|
||||
})
|
||||
|
||||
return Promise.resolve(response.data);
|
||||
} catch (e: any) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// on recipe route
|
||||
export const getRecipeByID = async (id: string | number) => {
|
||||
const result = await fetch(API + 'recipe/' + id).then(response => response.json());
|
||||
return result;
|
||||
try {
|
||||
const response = await axios({
|
||||
method: "GET",
|
||||
url: API + '/recipe/' + id
|
||||
})
|
||||
|
||||
return Promise.resolve(response.data);
|
||||
} catch (e: any) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export const getAllRecipes = async () => {
|
||||
const result = await fetch(API + 'recipe').then(response => response.json());
|
||||
return result;
|
||||
try {
|
||||
const response = await axios({
|
||||
method: "GET",
|
||||
url: API + '/recipe'
|
||||
})
|
||||
|
||||
return Promise.resolve(response.data);
|
||||
} catch (e: any) {
|
||||
throw e;
|
||||
}
|
||||
// const result = await fetch(API + 'recipe').then(response => response.json());
|
||||
// return result;
|
||||
}
|
||||
Reference in New Issue
Block a user