Update user info

This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-12-09 11:15:40 +01:00
parent dd4dda2957
commit 255880d40d
3 changed files with 68 additions and 2 deletions
+32
View File
@@ -0,0 +1,32 @@
import getXSRFToken from "../getXSRF.js";
export default async function updateUser(name, lastname, phone) {
const csrfToken = await getXSRFToken();
try {
const res = await fetch(`http://${import.meta.env.VITE_API_URL}/api/users/update`, {
method: 'POST',
credentials: 'include',
headers: {
'Accept': 'application/json',
'X-XSRF-TOKEN': csrfToken,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: name,
phone: phone,
lastname: lastname,
})
});
if (!res.ok) {
throw new Error(`Erreur serveur : ${res.status}`);
}
return await res.json();
} catch (err) {
console.error('Erreur :', err);
return null;
}
}