From 5b96e75ff68b0744f2bfe6ca1480acd60a42f907 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Fri, 11 Sep 2026 13:31:15 -0400 Subject: [PATCH] Use lt.api instead of raw fetch() in notification bell (#57) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit layout_footer.php's loadNotifications() and "mark all read" handler called fetch() directly instead of lt.api.*, violating the project's own documented convention (README Dev Notes #20). api/bootstrap.php rotates the CSRF token on every successful write and returns it in the response's csrf_token field; lt.api.* reads that and updates window.CSRF_TOKEN, but a raw fetch() never does — so after "mark all read", the server had rotated its token but the client's cached one was stale, causing the user's next write anywhere else in the app to fail once with "Invalid CSRF token" before self-healing. Replaced both fetch() calls with lt.api.get/post, which also drops the now-redundant manual header/credentials boilerplate. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Lhz7pGMaoTfL5sdYS5XiKv --- views/layout_footer.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/views/layout_footer.php b/views/layout_footer.php index 144b561..8992dd6 100644 --- a/views/layout_footer.php +++ b/views/layout_footer.php @@ -235,8 +235,7 @@ } function loadNotifications() { - return fetch('/api/notifications.php', { credentials: 'same-origin' }) - .then(function(r) { return r.json(); }) + return lt.api.get('/api/notifications.php') .then(function(data) { renderNotifications(data); return true; }) .catch(function() { list.innerHTML = '
Could not load
'; @@ -251,11 +250,7 @@ if (clearBtn) { clearBtn.addEventListener('click', function() { - fetch('/api/notifications.php', { - method: 'POST', credentials: 'same-origin', - headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': window.CSRF_TOKEN || '' }, - body: JSON.stringify({ action: 'mark_read' }) - }).then(loadNotifications); + lt.api.post('/api/notifications.php', { action: 'mark_read' }).then(loadNotifications); }); }