implement changes to commands and templates

This commit is contained in:
2026-04-08 14:20:54 +02:00
parent e90b8b4d85
commit 65a281dbcb
15 changed files with 326 additions and 59 deletions
+20 -1
View File
@@ -14,11 +14,21 @@ const createFetchError = async (response) => {
return error;
};
let csrfToken = null;
const setCsrfToken = (token) => {
csrfToken = typeof token === 'string' ? token : null;
};
const getCsrfToken = () => csrfToken;
const fetchJson = async (url, options = {}) => {
const method = (options.method || 'GET').toUpperCase();
const response = await fetch(url, {
credentials: 'include',
headers: {
'Content-Type': 'application/json',
...(csrfToken && method !== 'GET' && method !== 'HEAD' ? {'X-CSRF-Token': csrfToken} : {}),
...(options.headers || {}),
},
...options,
@@ -110,6 +120,7 @@ const initIndexPage = async () => {
try {
const data = await fetchJson('/api/me');
setCsrfToken(data.csrfToken);
sessionStatus.textContent = `Signed in as ${formatUserDisplay(data.user)}.`;
loginButton.hidden = true;
dashboardButton.hidden = false;
@@ -131,7 +142,13 @@ const initIndexPage = async () => {
logoutButton?.addEventListener('click', async () => {
try {
await fetch('/auth/logout', {method: 'POST', credentials: 'include'});
await fetch('/auth/logout', {
method: 'POST',
credentials: 'include',
headers: {
...(csrfToken ? {'X-CSRF-Token': csrfToken} : {}),
},
});
sessionStatus.textContent = 'Logged out successfully.';
loginButton.hidden = false;
dashboardButton.hidden = true;
@@ -151,6 +168,8 @@ document.addEventListener('DOMContentLoaded', () => {
window.dashboardApi = {
fetchJson,
setCsrfToken,
getCsrfToken,
showToast,
setErrorBanner,
clearErrorBanner,