CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is a security measure that helps protect applications from automated abuse, like bots spamming forms or attempting brute-force logins. By presenting challenges that are easy for humans to solve but hard for machines—such as identifying images or checking a box—CAPTCHAs ensure that real users, not scripts, are interacting with your service.

How to use it

First, you need to enable captcha in the Dynamic dashboard. Then, you can use the isCaptchaRequired and setCaptchaToken functions to check if captcha is required and set the captcha token respectively. You can implement captcha in your own way, just make sure you call setCaptchaToken when the captcha challenge is completed, and that you have it set before calling one of the sign-in functions from the SDK.

Checking if captcha is required

You can check if captcha is required to decide whether to prompt the user to complete a captcha challenge or not.
import { isCaptchaRequired } from '@dynamic-labs-sdk/client';

const isCaptchaRequired = isCaptchaRequired();

if (isCaptchaRequired) {
  // prompt the user to complete an captcha challenge
}

Setting the captcha token

Once the captcha challenge is completed, you can set the captcha token using the setCaptchaToken function. The SDK will read the captcha token when making the request to the server.
import { setCaptchaToken } from '@dynamic-labs-sdk/client';

const onCaptchaComplete = (captchaToken: string) => {
  setCaptchaToken(captchaToken);
};