- Introduced `createCaptchaRefreshLink` to trigger captcha token refresh automatically. - Removed redundant manual captcha refresh calls and integrated it into Apollo Provider.
20 lines
458 B
TypeScript
20 lines
458 B
TypeScript
import { ApolloLink } from '@apollo/client';
|
|
|
|
export const createCaptchaRefreshLink = (
|
|
requestFreshCaptchaToken: () => void,
|
|
) => {
|
|
return new ApolloLink((operation, forward) => {
|
|
const { variables } = operation;
|
|
|
|
const hasCaptchaToken = variables && 'captchaToken' in variables;
|
|
|
|
return forward(operation).map((response) => {
|
|
if (hasCaptchaToken) {
|
|
requestFreshCaptchaToken();
|
|
}
|
|
|
|
return response;
|
|
});
|
|
});
|
|
};
|