From 92bb10faba34e3502d409af64a7ca189a085edb0 Mon Sep 17 00:00:00 2001 From: F4ilji Date: Thu, 2 Jul 2026 13:17:24 +0500 Subject: [PATCH] fix: add CSRF token and cookies to deploy API requests --- resources/js/Pages/Dashboard/Deploy/Index.vue | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/resources/js/Pages/Dashboard/Deploy/Index.vue b/resources/js/Pages/Dashboard/Deploy/Index.vue index b0ab0c2..907a312 100644 --- a/resources/js/Pages/Dashboard/Deploy/Index.vue +++ b/resources/js/Pages/Dashboard/Deploy/Index.vue @@ -15,9 +15,23 @@ const status = ref({ let pollingInterval = null +const getCsrfToken = () => { + const match = document.cookie.match(/XSRF-TOKEN=([^;]+)/) + return match ? decodeURIComponent(match[1]) : '' +} + +const headers = { + 'Content-Type': 'application/json', + 'X-XSRF-TOKEN': getCsrfToken(), + 'Accept': 'application/json', +} + const fetchStatus = async () => { try { - const response = await fetch('/api/deploy/status') + const response = await fetch('/api/deploy/status', { + credentials: 'same-origin', + headers, + }) status.value = await response.json() if (!status.value.running && pollingInterval) { @@ -31,7 +45,11 @@ const fetchStatus = async () => { const startDeploy = async () => { try { - const response = await fetch('/api/deploy', { method: 'POST' }) + const response = await fetch('/api/deploy', { + method: 'POST', + credentials: 'same-origin', + headers, + }) const data = await response.json() if (response.ok) {