fix: add credentials: include to admin fetch calls for cookie consistency

This commit is contained in:
dimitar 2026-07-29 20:06:28 +02:00
parent faa8216716
commit 7046c3375f
3 changed files with 8 additions and 6 deletions

View File

@ -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");
};

View File

@ -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

View File

@ -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) {