<SignUp />
component
The <SignUp />
component renders a UI for signing up users. The functionality of the <SignUp />
component is controlled by the instance settings you specify in your Clerk Dashboard(opens in a new tab), such as sign-in and sign-up options and social connections. You can further customize your <SignUp />
component by passing additional properties at the time of rendering.
Properties
All props are optional.
Name | Type | Description |
---|---|---|
appearance | Appearance | undefined | Optional object to style your components. Will only affect Clerk Components and not Account Portal pages. |
routing | 'hash' | 'path' | 'virtual' | The routing strategy for your pages. Note: If you are using environment variables for Next.js or Remix to specify your routes, this will be set to path . |
path | string | The path where the component is mounted on when path-based routing is used For example, /sign-up This prop is ignored in hash- and virtual-based routing. |
redirectUrl | string | Full URL or path to navigate to after successful sign in or sign up. The same as setting afterSignInUrl and afterSignUpUrl to the same value. |
afterSignInUrl | string | The full URL or path to navigate to after a successful sign in. Defaults to / . It's recommended to use the environment variable instead. |
signInUrl | string | Full URL or path to the sign in page. Use this property to provide the target of the 'Sign In' link that's rendered. It's recommended to use the environment variable instead. |
afterSignUpUrl | string | The full URL or path to navigate to after a successful sign up. Defaults to / . It's recommended to use the environment variable instead. |
unsafeMetadata | object | An object with the key and value for unsafeMetadata that will be saved to the user after sign up. E.g. { "company": "companyID1234" } |
initialValues | SignUpInitialValues | The values used to prefill the sign-up fields with. |
Usage with frameworks
The following example includes basic implementation of the <SignIn />
component. You can use this as a starting point for your own implementation.
You can embed the <SignUp />
component using the Next.js optional catch-all route(opens in a new tab). This allows you to redirect the user inside your application. The <SignUp />
component should be mounted on a public page.
/app/sign-up/[[...sign-up]]/page.tsximport { SignUp } from "@clerk/nextjs"; export default function Page() { return <SignUp path="/sign-up" signInUrl="/sign-in" />; }
You will notice a path
prop is being passed to the SignUp />
component. This is because, by default, the routing
strategy is set to path
, requiring the path
prop to be passed. In Next.js applications, you can either pass the path
prop to the <SignUp />
component, or you can define the NEXT_PUBLIC_CLERK_SIGN_IN_URL
and NEXT_PUBLIC_CLERK_SIGN_UP_URL
environment variables.
The example below shows how to mount the <SignUp />
component on a page without a path
prop. Select the .env.local
tab to see an example of how to define the appropriate environment variables.
/pages/sign-up/[[...index]].tsximport { SignUp } from "@clerk/nextjs"; const SignUpPage = () => ( <SignUp /> ); export default SignUpPage;
.env.localCLERK_SIGN_IN_URL=/sign-in CLERK_SIGN_UP_URL=/sign-up
sign-up.jsximport { SignUp } from "@clerk/clerk-react"; function SignUpPage() { return <SignUp path="/sign-up" />; }
app/routes/sign-up/$.tsximport { SignUp } from "@clerk/remix"; export default function SignUpPage() { return ( <div style={{ border: "2px solid blue", padding: "2rem" }}> <h1>Sign Up route</h1> <SignUp path="/sign-up" /> </div> ); }
/pages/sign-up.jsimport { SignUp } from "gatsby-plugin-clerk"; export default function SignUpPage() { return ( <div style={{ border: "2px solid blue", padding: "2rem" }}> <h1>Sign Up route</h1> <SignUp path="/sign-up" /> </div> ); }
Usage with JavaScript
The following methods available on an instance of the Clerk
class are used to render and control the <SignUp />
component:
The following examples assume that you have followed the quickstart in order to add Clerk to your JavaScript application.
mountSignUp()
Render the <SignUp />
component to an HTML <div>
element.
function mountSignUp(node: HTMLDivElement, props?: SignUpProps): void;
mountSignUp()
params
Name | Type | Description |
---|---|---|
node | HTMLDivElement (opens in a new tab) | The <div> element used to render in the <SignUp /> component |
props? | SignUpProps | The properties to pass to the <SignUp /> component. |
mountSignUp()
usage
index.tsimport Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); document.getElementById("app").innerHTML = ` <div id="sign-up"></div> `; const signUpDiv = document.getElementById("sign-up"); clerk.mountSignUp(signUpDiv);
index.js<!-- Add a <div id="sign-up"> element to your HTML --> <div id="sign-up"></div> <!-- Initialize Clerk with your Clerk Publishable key and Frontend API URL --> <script async crossorigin="anonymous" data-clerk-publishable-key="{{pub_key}}" src="https://{{fapi_url}}/npm/@clerk/clerk-js@latest/dist/clerk.browser.js" type="text/javascript" ></script> <script> window.addEventListener("load", async function () { await Clerk.load(); const signUpDiv = document.getElementById('sign-up'); Clerk.mountSignUp(signUpDiv); }); </script>
unmountSignUp()
Unmount and run cleanup on an existing <SignUp />
component instance.
function unmountSignUp(node: HTMLDivElement): void;
unmountSignUp()
params
Name | Type | Description |
---|---|---|
node | HTMLDivElement (opens in a new tab) | The container <div> element with a rendered <SignUp /> component instance |
unmountSignUp()
usage
index.tsimport Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); document.getElementById("app").innerHTML = ` <div id="sign-up"></div> `; const signUpDiv = document.getElementById("sign-up"); clerk.mountSignUp(signUpDiv); // ... clerk.unmountSignUp(signUpDiv);
index.js<!-- Add a <div id="sign-up"> element to your HTML --> <div id="sign-up"></div> <!-- Initialize Clerk with your Clerk Publishable key and Frontend API URL --> <script async crossorigin="anonymous" data-clerk-publishable-key="{{pub_key}}" src="https://{{fapi_url}}/npm/@clerk/clerk-js@latest/dist/clerk.browser.js" type="text/javascript" ></script> <script> window.addEventListener("load", async function () { await Clerk.load(); const signUpDiv = document.getElementById('sign-up'); Clerk.mountSignUp(signUpDiv); // ... Clerk.unmountSignUp(signUpDiv); }); </script>
openSignUp()
Opens the <SignUp />
component as an overlay at the root of your HTML body
element.
function openSignUp(props?: SignUpProps): void;
openSignUp()
params
Name | Type | Description |
---|---|---|
props? | SignUpProps | The properties to pass to the <SignUp /> component |
openSignUp()
usage
index.tsimport Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); clerk.openSignUp();
index.html<!-- Initialize Clerk with your Clerk Publishable key and Frontend API URL --> <script async crossorigin="anonymous" data-clerk-publishable-key="{{pub_key}}" src="https://{{fapi_url}}/npm/@clerk/clerk-js@latest/dist/clerk.browser.js" type="text/javascript" ></script> <script> window.addEventListener("load", async function () { await Clerk.load(); Clerk.openSignUp(); }); </script>
closeSignUp()
Closes the sign up overlay.
function closeSignUp(): void;
closeSignUp()
usage
index.tsimport Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); clerk.openSignUp(); // ... clerk.closeSignUp();
index.html<!-- Initialize Clerk with your Clerk Publishable key and Frontend API URL --> <script async crossorigin="anonymous" data-clerk-publishable-key="{{pub_key}}" src="https://{{fapi_url}}/npm/@clerk/clerk-js@latest/dist/clerk.browser.js" type="text/javascript" ></script> <script> window.addEventListener("load", async function () { await Clerk.load(); Clerk.openSignUp(); // ... Clerk.closeSignUp(); }); </script>
Customization
To learn about how to customize Clerk components, see the customization documentation.
Last updated on April 15, 2024