use fetchWrapper for users routes
This commit is contained in:
1 parent
a0bba2deb4
commit
79e765dd96
5 files changed
+26
-102
No files matched your search
@@ -1,31 +1,13 @@
|
||||
import fetchWrapper from "../fetchWrapper.js";
|
||||
import getXSRFToken from "../getXSRF.js";
|
||||
|
||||
export default async function deleteUser() {
|
||||
const csrfToken = await getXSRFToken();
|
||||
|
||||
try {
|
||||
const response = await fetch(`${import.meta.env.VITE_API_URL}/api/users`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-XSRF-TOKEN': csrfToken,
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
return {
|
||||
status: response.status,
|
||||
errors: data.errors || data.message
|
||||
};
|
||||
}
|
||||
|
||||
return { status: response.status, data };
|
||||
|
||||
} catch (error) {
|
||||
return { status: 500, error };
|
||||
}
|
||||
return fetchWrapper(
|
||||
"/api/users",
|
||||
null,
|
||||
"DELETE",
|
||||
{ "X-XSRF-TOKEN": csrfToken }
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user