diff --git a/src/app/admin/(panel)/AdminSidebar.tsx b/src/app/admin/(panel)/AdminSidebar.tsx index d1c83a3..372a100 100644 --- a/src/app/admin/(panel)/AdminSidebar.tsx +++ b/src/app/admin/(panel)/AdminSidebar.tsx @@ -13,7 +13,7 @@ export default function AdminSidebar({ username, role }: Props) { const pathname = usePathname(); const handleLogout = async () => { - await fetch("/api/admin/logout", { method: "POST" }); + await fetch("/api/admin/logout", { method: "POST", credentials: "include" }); router.push("/admin/login"); }; diff --git a/src/app/admin/(panel)/codes/page.tsx b/src/app/admin/(panel)/codes/page.tsx index 1b895b4..dd900a0 100644 --- a/src/app/admin/(panel)/codes/page.tsx +++ b/src/app/admin/(panel)/codes/page.tsx @@ -21,7 +21,7 @@ export default function AdminCodesPage() { const fetchCodes = async () => { setLoading(true); try { - const res = await fetch("/api/admin/codes"); + const res = await fetch("/api/admin/codes", { credentials: "include" }); if (res.ok) { setCodes(await res.json()); } @@ -41,7 +41,7 @@ export default function AdminCodesPage() { setError(""); setNewCode(""); try { - const res = await fetch("/api/admin/codes", { method: "POST" }); + const res = await fetch("/api/admin/codes", { method: "POST", credentials: "include" }); const data = await res.json(); if (!res.ok) { throw new Error(data.error || "Грешка при генерирање"); @@ -58,7 +58,7 @@ export default function AdminCodesPage() { const handleDelete = async (id: string) => { if (!confirm("Дали сте сигурни?")) return; try { - await fetch(`/api/admin/codes/${id}`, { method: "DELETE" }); + await fetch(`/api/admin/codes/${id}`, { method: "DELETE", credentials: "include" }); fetchCodes(); } catch { // ignore diff --git a/src/app/admin/(panel)/users/page.tsx b/src/app/admin/(panel)/users/page.tsx index a3d5c5b..2978925 100644 --- a/src/app/admin/(panel)/users/page.tsx +++ b/src/app/admin/(panel)/users/page.tsx @@ -20,7 +20,7 @@ export default function AdminUsersPage() { const fetchUsers = async () => { setLoading(true); try { - const res = await fetch("/api/admin/users"); + const res = await fetch("/api/admin/users", { credentials: "include" }); if (res.ok) { setUsers(await res.json()); } @@ -42,6 +42,7 @@ export default function AdminUsersPage() { const res = await fetch("/api/admin/users", { method: "POST", headers: { "Content-Type": "application/json" }, + credentials: "include", body: JSON.stringify({ username: newUsername, password: newPassword }), }); if (!res.ok) { @@ -60,7 +61,7 @@ export default function AdminUsersPage() { const handleDelete = async (id: string) => { if (!confirm("Дали сте сигурни дека сакате да го избришете овој администратор?")) return; try { - const res = await fetch(`/api/admin/users/${id}`, { method: "DELETE" }); + const res = await fetch(`/api/admin/users/${id}`, { method: "DELETE", credentials: "include" }); if (res.ok) { fetchUsers(); } @@ -79,6 +80,7 @@ export default function AdminUsersPage() { const res = await fetch(`/api/admin/users/${id}`, { method: "PUT", headers: { "Content-Type": "application/json" }, + credentials: "include", body: JSON.stringify({ password: newPw }), }); if (res.ok) {