Ajout de la connexion utilisateur

This commit is contained in:
Dayamond
2025-10-18 16:48:27 +02:00
parent 05eed05947
commit 387b2c32cf
4 changed files with 86 additions and 5 deletions
+33
View File
@@ -0,0 +1,33 @@
import getXSRFToken from "./getXSRF.js";
export default async function login(email, password) {
const csrfToken = await getXSRFToken();
await fetch('http://localhost:8000/api/login', {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'X-XSRF-TOKEN': csrfToken,
'Accept': 'application/json'
},
body: JSON.stringify({
email: email,
password: password
})
})
.then(response => {
console.log('Code HTTP :', response.status);
if (!response.ok) {
throw new Error(`Erreur HTTP ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Connexion réussie ! Données utilisateur :', data);
})
.catch(error => {
console.error('Erreur lors de la connexion :', error.message);
});
}