Files
parenthese/frontend/src/api/authApi.js
T
IliesAllaliandClaude Opus 5.5 1b2d8ed6e2 feat(comptes): ALLOW_REGISTRATION ferme la création de compte (#113)
À false, POST /auth/register répond 403 registration_closed et l'app ne
propose plus de créer un compte (accueil, connexion, porte d'un arbre
partagé, menu du visiteur). Les comptes existants se connectent et créent
leurs arbres, le partage par lien et mot de passe ne change pas.

Une instance sans aucun compte accepte quand même le premier, sous un
verrou de transaction PostgreSQL (deux inscriptions simultanées n'en
créent qu'un). GET /auth/options expose l'état à l'écran d'accueil.

Défaut true : rien ne change pour les instances existantes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 14:12:18 +02:00

83 lines
1.8 KiB
JavaScript

import { apiRequest } from './client'
export async function loginUser(email, password) {
const data = await apiRequest('/auth/login', {
method: 'POST',
body: JSON.stringify({ email, password }),
})
return data
}
export async function registerUser(firstName, email, password) {
const data = await apiRequest('/auth/register', {
method: 'POST',
body: JSON.stringify({ firstName, email, password }),
})
return data
}
export async function logoutUser(token) {
const data = await apiRequest('/auth/logout', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
},
})
return data
}
export async function deleteAccount(token, password) {
const data = await apiRequest('/auth/me', {
method: 'DELETE',
headers: {
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({ password }),
})
return data
}
// Profil du compte connecté (prénom compris), pour une session restaurée sur un autre appareil
export async function fetchAccountProfile(token) {
const data = await apiRequest('/auth/me', {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
},
})
return data
}
export async function fetchLastOpenedTree(token) {
const data = await apiRequest('/auth/me/last-tree', {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
},
})
return data?.lastTree || null
}
export async function updateLastOpenedTree(token, payload) {
const data = await apiRequest('/auth/me/last-tree', {
method: 'PUT',
headers: {
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(payload),
})
return data?.lastTree || null
}
// Options de l'instance : inscription ouverte ou fermée (ALLOW_REGISTRATION côté API)
export async function fetchAuthOptions() {
return apiRequest('/auth/options', { method: 'GET' })
}