csrf.ts 550 B

12345678910111213141516171819202122
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ApolloLink } from '@apollo/client/core'
  3. import { setCSRFToken } from '../utils/csrfToken.ts'
  4. const csrfLink = new ApolloLink((operation, forward) => {
  5. return forward(operation).map((response) => {
  6. const context = operation.getContext()
  7. if (context.response) {
  8. const csrfToken = context.response.headers.get('CSRF-Token')
  9. if (csrfToken) {
  10. setCSRFToken(csrfToken)
  11. }
  12. }
  13. return response
  14. })
  15. })
  16. export default csrfLink