Skip to content

The open alternative to Salesforce, designed for AI.

523 B
Raw Blame
import { ApolloLink } from '@apollo/client';
import { map } from 'rxjs';

export const createCaptchaRefreshLink = (
  requestFreshCaptchaToken: () => void,
) => {
  return new ApolloLink((operation, forward) => {
    const { variables } = operation;

    const hasCaptchaToken = variables != null && 'captchaToken' in variables;

    return forward(operation).pipe(
      map((response) => {
        if (hasCaptchaToken) {
          requestFreshCaptchaToken();
        }

        return response;
      }),
    );
  });
};