Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to clerkstage.dev

Smart bot sign-up protection

When using the Smart option at User & Authentication > Attack Protection > Bot sign-up protection in Clerk Dashboard, it's important to include a specific element in your DOM to facilitate the rendering of the CAPTCHA widget.

Clerk SDK expects a <div id="clerk-captcha" /> element to be present when you use the signUp.create() method. This div acts as a placeholder where the CAPTCHA widget is rendered.

If the <div id="clerk-captcha" /> element is not found, the Clerk SDK automatically resorts to using an Invisible CAPTCHA.

Example

import { useState } from "react"; import { useSignUp } from "@clerk/nextjs"; import { useRouter } from "next/router"; export default function SignUpForm() { const { isLoaded, signUp, setActive } = useSignUp(); const [emailAddress, setEmailAddress] = useState(""); const [password, setPassword] = useState(""); const [pendingVerification, setPendingVerification] = useState(false); const [code, setCode] = useState(""); const router = useRouter(); // start the sign up process. const handleSubmit = async (e) => { e.preventDefault(); if (!isLoaded) { return; } try { await signUp.create({ emailAddress, password, }); // send the email. await signUp.prepareEmailAddressVerification({ strategy: "email_code" }); // change the UI to our pending section. setPendingVerification(true); } catch (err: any) { console.error(JSON.stringify(err, null, 2)); } }; // This verifies the user using email code that is delivered. const onPressVerify = async (e) => { e.preventDefault(); if (!isLoaded) { return; } try { const completeSignUp = await signUp.attemptEmailAddressVerification({ code, }); if (completeSignUp.status !== "complete") { /* investigate the response, to see if there was an error or if the user needs to complete more steps.*/ console.log(JSON.stringify(completeSignUp, null, 2)); } if (completeSignUp.status === "complete") { await setActive({ session: completeSignUp.createdSessionId }) router.push("/"); } } catch (err: any) { console.error(JSON.stringify(err, null, 2)); } }; return ( <div> {!pendingVerification && ( <form> <div> <label htmlFor="email">Email</label> <input onChange={(e) => setEmailAddress(e.target.value)} id="email" name="email" type="email" /> </div> <div> <label htmlFor="password">Password</label> <input onChange={(e) => setPassword(e.target.value)} id="password" name="password" type="password" /> </div> {/* CAPTCHA Widget */} <div id="clerk-captcha"></div> <button onClick={handleSubmit}>Sign up</button> </form> )} {pendingVerification && ( <div> <form> <input value={code} placeholder="Code..." onChange={(e) => setCode(e.target.value)} /> <button onClick={onPressVerify}> Verify Email </button> </form> </div> )} </div> ); }

What did you think of this content?

Clerk © 2024