feat: append csrf to formdata
This commit is contained in:
parent
655d1f899b
commit
d0007d1b3d
|
|
@ -56,7 +56,7 @@ export function FollowForm({ type }: { type: string }) {
|
|||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
keyword: prefix,
|
||||
keyword: prefix || "",
|
||||
},
|
||||
})
|
||||
const mutation = useMutation({
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@ import { getCsrfToken } from "@hono/auth-js/react"
|
|||
|
||||
export const apiFetch = ofetch.create({
|
||||
baseURL: import.meta.env.VITE_API_URL,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
credentials: "include",
|
||||
onRequest: async ({ options }) => {
|
||||
if (options.method && options.method.toLowerCase() !== "get") {
|
||||
|
|
@ -13,7 +10,11 @@ export const apiFetch = ofetch.create({
|
|||
if (!options.body) {
|
||||
options.body = {}
|
||||
}
|
||||
;(options.body as Record<string, any>).csrfToken = csrfToken
|
||||
if (options.body instanceof FormData) {
|
||||
options.body.append("csrfToken", csrfToken)
|
||||
} else {
|
||||
;(options.body as Record<string, any>).csrfToken = csrfToken
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue