import getXSRFToken from "../getXSRF.js";

export default async function logout() {

    const csrfToken = await getXSRFToken();

    try {
        const response = await fetch(`http://${import.meta.env.VITE_API_URL}/api/users/logout`, {
            method: 'POST',
            credentials: 'include',
            headers: {
                'Content-Type': 'application/json',
                'Accept': 'application/json',
                'X-XSRF-TOKEN': csrfToken
            },
        });

        console.log('Code HTTP :', response.status);

        if (!response.ok) {
            throw new Error(`Erreur HTTP ${response.status}`);
        }

        return { status: response.status };
    } catch (error) {
        return error;
    }
}
