| 32 | CSRF UTILITIES (shared) |
| 33 | ========================= */ |
| 34 | export function setCsrfToken(token) { |
| 35 | if (!token) return; |
| 36 | window.csrfToken = token; |
| 37 | localStorage.setItem('csrf', token); |
| 38 | |
| 39 | // meta tag for easy access in other places |
| 40 | let meta = document.querySelector('meta[name="csrf-token"]'); |
| 41 | if (!meta) { |
| 42 | meta = document.createElement('meta'); |
| 43 | meta.name = 'csrf-token'; |
| 44 | document.head.appendChild(meta); |
| 45 | } |
| 46 | meta.content = token; |
| 47 | } |
| 48 | |
| 49 | export function getCsrfToken() { |
| 50 | return window.csrfToken || localStorage.getItem('csrf') || ''; |