csrf.ts 549 B

123456789101112131415161718192021
  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