incription , connection
This commit is contained in:
23
frontend/src/services/auth.js
Normal file
23
frontend/src/services/auth.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const BASE = '/api/auth'
|
||||
|
||||
export async function loginApi({ email, password }) {
|
||||
const res = await fetch(`${BASE}/login`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email, password }),
|
||||
})
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw new Error(data.message || 'Erreur de connexion.')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function registerApi({ email, firstname, lastname, password }) {
|
||||
const res = await fetch(`${BASE}/register`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email, firstname, lastname, password }),
|
||||
})
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw new Error(data.message || "Erreur lors de l'inscription.")
|
||||
return data
|
||||
}
|
||||
Reference in New Issue
Block a user