various fixes for checkout

This commit is contained in:
Codex Agent
2025-12-22 21:51:34 +01:00
parent c8f0f880d2
commit 0f2604309d
12 changed files with 681 additions and 277 deletions

View File

@@ -32,7 +32,17 @@ type SharedPageProps = {
type FieldErrors = Record<string, string>;
const csrfToken = () => (document.querySelector('meta[name="csrf-token"]') as HTMLMetaElement | null)?.content ?? "";
const metaCsrfToken = () =>
(document.querySelector('meta[name="csrf-token"]') as HTMLMetaElement | null)?.content ?? "";
const xsrfCookieToken = () => {
if (typeof document === "undefined") {
return "";
}
const match = document.cookie.match(/(?:^|; )XSRF-TOKEN=([^;]*)/);
return match ? decodeURIComponent(match[1]) : "";
};
export default function LoginForm({ onSuccess, canResetPassword = true, locale, packageId }: LoginFormProps) {
const page = usePage<SharedPageProps>();
@@ -91,12 +101,19 @@ export default function LoginForm({ onSuccess, canResetPassword = true, locale,
setIsSubmitting(true);
try {
const cookieToken = xsrfCookieToken();
const metaToken = metaCsrfToken();
const response = await fetch(loginEndpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"X-CSRF-TOKEN": csrfToken(),
...(cookieToken
? { "X-XSRF-TOKEN": cookieToken }
: metaToken
? { "X-CSRF-TOKEN": metaToken }
: {}),
},
credentials: "same-origin",
body: JSON.stringify({