mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
CSRF implementation on server helpers
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { getAuthHeaders, getServerURL } from "@/lib/utils";
|
||||
import { getCsrfToken, getServerURL } from "@/lib/utils";
|
||||
import type { ServerQueryInput } from "..";
|
||||
|
||||
export async function create({
|
||||
@@ -20,8 +20,13 @@ export async function create({
|
||||
url.searchParams.set("userId", `${userId}`);
|
||||
if (description.trim() !== "") url.searchParams.set("description", description.trim());
|
||||
|
||||
const csrfToken = getCsrfToken();
|
||||
const headers: HeadersInit = {};
|
||||
if (csrfToken) headers["X-CSRF-Token"] = csrfToken;
|
||||
|
||||
const res = await fetch(url.toString(), {
|
||||
headers: getAuthHeaders(),
|
||||
headers,
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
|
||||
Reference in New Issue
Block a user