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

export default async function readNotifications() {

    const csrfToken = await getXSRFToken();

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

        if (!res.ok) {
            throw new Error(`Erreur serveur : ${res.status}`);
        }

        return await res.json();
    } catch (err) {
        console.error('Erreur :', err);
        return null;
    }
}