fix: add credentials: include to admin fetch calls for cookie consistency
This commit is contained in:
parent
faa8216716
commit
7046c3375f
@ -13,7 +13,7 @@ export default function AdminSidebar({ username, role }: Props) {
|
|||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
await fetch("/api/admin/logout", { method: "POST" });
|
await fetch("/api/admin/logout", { method: "POST", credentials: "include" });
|
||||||
router.push("/admin/login");
|
router.push("/admin/login");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ export default function AdminCodesPage() {
|
|||||||
const fetchCodes = async () => {
|
const fetchCodes = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/admin/codes");
|
const res = await fetch("/api/admin/codes", { credentials: "include" });
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
setCodes(await res.json());
|
setCodes(await res.json());
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ export default function AdminCodesPage() {
|
|||||||
setError("");
|
setError("");
|
||||||
setNewCode("");
|
setNewCode("");
|
||||||
try {
|
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();
|
const data = await res.json();
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(data.error || "Грешка при генерирање");
|
throw new Error(data.error || "Грешка при генерирање");
|
||||||
@ -58,7 +58,7 @@ export default function AdminCodesPage() {
|
|||||||
const handleDelete = async (id: string) => {
|
const handleDelete = async (id: string) => {
|
||||||
if (!confirm("Дали сте сигурни?")) return;
|
if (!confirm("Дали сте сигурни?")) return;
|
||||||
try {
|
try {
|
||||||
await fetch(`/api/admin/codes/${id}`, { method: "DELETE" });
|
await fetch(`/api/admin/codes/${id}`, { method: "DELETE", credentials: "include" });
|
||||||
fetchCodes();
|
fetchCodes();
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export default function AdminUsersPage() {
|
|||||||
const fetchUsers = async () => {
|
const fetchUsers = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/admin/users");
|
const res = await fetch("/api/admin/users", { credentials: "include" });
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
setUsers(await res.json());
|
setUsers(await res.json());
|
||||||
}
|
}
|
||||||
@ -42,6 +42,7 @@ export default function AdminUsersPage() {
|
|||||||
const res = await fetch("/api/admin/users", {
|
const res = await fetch("/api/admin/users", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
credentials: "include",
|
||||||
body: JSON.stringify({ username: newUsername, password: newPassword }),
|
body: JSON.stringify({ username: newUsername, password: newPassword }),
|
||||||
});
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
@ -60,7 +61,7 @@ export default function AdminUsersPage() {
|
|||||||
const handleDelete = async (id: string) => {
|
const handleDelete = async (id: string) => {
|
||||||
if (!confirm("Дали сте сигурни дека сакате да го избришете овој администратор?")) return;
|
if (!confirm("Дали сте сигурни дека сакате да го избришете овој администратор?")) return;
|
||||||
try {
|
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) {
|
if (res.ok) {
|
||||||
fetchUsers();
|
fetchUsers();
|
||||||
}
|
}
|
||||||
@ -79,6 +80,7 @@ export default function AdminUsersPage() {
|
|||||||
const res = await fetch(`/api/admin/users/${id}`, {
|
const res = await fetch(`/api/admin/users/${id}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
credentials: "include",
|
||||||
body: JSON.stringify({ password: newPw }),
|
body: JSON.stringify({ password: newPw }),
|
||||||
});
|
});
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user