Clerk Elements currently only works with Next.js App Router and Clerk Core 2. As it gets closer to a stable release, support for additional frameworks will be added.
Create a new route in your Next.js application. The route needs to be an optional catch-all route so the sign-up flow can handled nested paths, as shown in the following example:
You will use these two imports to build out the rest of the flow. <SignUp.Root> manages the sign-up state and handles connecting the components to Clerk's APIs.
Tip
If you're getting TypeScript errors on the @clerk/elements imports you probably have forgotten to set your moduleResolution in tsconfig.json to bundler.
The Clerk authentication flows are made up of steps. Steps handle rendering the UI for each part of the flow. To allow users to create a sign-up attempt, the start step needs to be rendered. The following example does so with the <SignUp.Step> component:
Make it functional by adding input fields. The following example uses the <Clerk.Field> component to render the emailAddress and username fields, as well as the <Connection> component to allow users to sign up with a social connection, like Google:
<Clerk.Field> takes care of wiring up the input with the label element, and <Clerk.FieldError> will render any field-specific errors that get returned from Clerk's API. The <SignUp.Action> component provides common actions that are used throughout the flows. In this case, using the submit action to render a submit button for the start form.
As users progress through a sign-up attempt, they may be asked to verify a number of authentication factors in the verifications step. You can render a form for the user to complete verification, but each verification strategy requires different fields. You must render the form fields conditionally for each authentication strategy your instance supports using the <SignIn.Strategy> component.
The following example demonstrates how to conditionally render a form for the phone_code and email_code strategies:
Verification is the final step in the sign-up flow. When a user has verified all required factors, the sign-up attempt will be complete, their account will be created, and they will be signed in.
Should a user attempt to sign up via Google while a username is a required field, the continue step will be necessary to accept the username. The <SignUp.Step> component will display any additional required fields.
If your instance has additional required fields, you can add them the same way you added the username field to the continue step.
Note
Under the hood, Clerk Elements will conditionally render the fields that are necessary to complete the sign up attempt, so there's no need to check the state of the sign up attempt yourself.