Remove all Django-specific naming from mizan-react
Renamed: DjangoError → MizanError DjangoHTTPClient → MizanHTTPClient DjangoFormState → MizanFormState DjangoFormsetState → MizanFormsetState createDjangoCSRClient → createMizanCSRClient createDjangoSSRClient → createMizanSSRClient ensureDjangoSession → ensureMizanSession useDjangoCSRClient → useMizanCSRClient TDjangoMessage → TServerMessage Made CSRF configurable: configureCsrf(cookieName, headerName) — defaults to Django conventions but works with any backend that uses CSRF tokens. Cookie name and header name are no longer hardcoded. All old names preserved as deprecated aliases in index.ts exports for backwards compatibility. Removed dead RouterAdapter re-export (file moved to legacy/). 33 React tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,9 +2,28 @@
|
||||
* Shared utilities used across mizan-react.
|
||||
*/
|
||||
|
||||
/** Default CSRF cookie name. Configurable via MizanProvider. */
|
||||
let _csrfCookieName = 'csrftoken'
|
||||
|
||||
/** Default CSRF header name. Configurable via MizanProvider. */
|
||||
let _csrfHeaderName = 'X-CSRFToken'
|
||||
|
||||
export function configureCsrf(cookieName: string, headerName: string): void {
|
||||
_csrfCookieName = cookieName
|
||||
_csrfHeaderName = headerName
|
||||
}
|
||||
|
||||
export function getCsrfCookieName(): string {
|
||||
return _csrfCookieName
|
||||
}
|
||||
|
||||
export function getCsrfHeaderName(): string {
|
||||
return _csrfHeaderName
|
||||
}
|
||||
|
||||
/** Extract CSRF token from cookies. Returns null during SSR. */
|
||||
export function getCSRFToken(): string | null {
|
||||
if (typeof document === 'undefined') return null
|
||||
const match = document.cookie.match(/csrftoken=([^;]+)/)
|
||||
const match = document.cookie.match(new RegExp(`${_csrfCookieName}=([^;]+)`))
|
||||
return match?.[1] ?? null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user