csrfToken.ts 506 B

123456789101112131415161718
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. const csrfTokenMetaElement: Maybe<HTMLMetaElement> = document.querySelector(
  3. 'meta[name="csrf-token"]',
  4. )
  5. const initialCsrfToken = csrfTokenMetaElement
  6. ? csrfTokenMetaElement.getAttribute('content')
  7. : null
  8. let csrfToken: Maybe<string> = null
  9. export const setCSRFToken = (newCSRFToken: string) => {
  10. csrfToken = newCSRFToken
  11. }
  12. export const getCSRFToken = (): Maybe<string> => {
  13. return csrfToken || initialCsrfToken
  14. }