<SignIn />
component
The <SignIn />
component renders a UI for signing in users. The functionality of the <SignIn />
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 <SignIn />
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. Defaults to 'path' . |
path | string | The path where the component is mounted on when path-based routing is used. This prop will be required for Next.js and Remix applications that do not set the appropriate environment variables, and is required for all other SDK's. This prop is ignored in hash- and virtual-based routing. |
redirectUrl | string | Full URL or path to navigate 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 after a successful sign in. Defaults to / . It's recommended to use the environment variable instead. |
signUpUrl | string | Full URL or path to the sign up page. Use this property to provide the target of the 'Sign Up' link that's rendered. It's recommended to use the environment variable instead. |
afterSignUpUrl | string | The full URL or path to navigate after a successful sign up. Defaults to / . It's recommended to use the environment variable instead. |
initialValues | SignInInitialValues | The values used to prefill the sign-in 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 <SignIn />
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 <SignIn />
component should be mounted on a public page.
/app/sign-in/[[...sign-in]]/page.tsximport { SignIn } from "@clerk/nextjs"; export default function Page() { return <SignIn path="/sign-in" signUpUrl="/sign-up" /> };
You will notice a path
prop is being passed to the SignIn />
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 <SignIn />
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 <SignIn />
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.
/app/sign-in/[[...sign-in]]/page.tsximport { SignIn } from "@clerk/nextjs"; export default function Page() { return <SignIn />; }
.env.localNEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
/src/sign-in/[[...index]].tsximport { SignIn } from "@clerk/clerk-react"; const SignInPage = () => ( <SignIn path="/sign-in" /> ); export default SignInPage;
app/routes/sign-in/$.tsximport { SignIn } from "@clerk/remix"; export default function SignInPage() { return ( <div style={{ border: "2px solid blue", padding: "2rem" }}> <h1>Sign In route</h1> <SignIn path="/sign-in" /> </div> ); }
/pages/sign-in.jsimport { SignIn } from "gatsby-plugin-clerk"; export default function SignInPage() { return ( <div style={{ border: "2px solid blue", padding: "2rem" }}> <h1>Sign In Up route</h1> <SignIn path="/sign-in" /> </div> ); }
Usage with JavaScript
The following methods available on an instance of the Clerk
class are used to render and control the <SignIn />
component:
The following examples assume that you have followed the quickstart in order to add Clerk to your JavaScript application.
mountSignIn()
Render the <SignIn />
component to an HTML <div>
element.
function mountSignIn(node: HTMLDivElement, props?: SignInProps): void;
mountSignIn()
params
Name | Type | Description |
---|---|---|
node | HTMLDivElement (opens in a new tab) | The container <div> element used to render in the <SignIn /> component |
props? | SignInProps | The properties to pass to the <SignIn /> component |
mountSignIn()
usage
index.jsimport 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-in"></div> `; const signInDiv = document.getElementById("sign-in"); clerk.mountSignIn(signInDiv);
index.html<!-- Add a <div id="sign-in"> element to your HTML --> <div id="sign-in"></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 signInDiv = document.getElementById('sign-in'); Clerk.mountSignIn(signInDiv); }); </script>
unmountSignIn()
Unmount and run cleanup on an existing <SignIn />
component instance.
function unmountSignIn(node: HTMLDivElement): void;
unmountSignIn()
params
Name | Type | Description |
---|---|---|
node | HTMLDivElement (opens in a new tab) | The container <div> element with a rendered <SignIn /> component instance |
unmountSignIn()
usage
index.jsimport 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-in"></div> ` const signInDiv = document.getElementById('sign-in'); clerk.mountSignIn(signInDiv); // ... clerk.unmountSignIn(signInDiv);
index.html<!-- Add a <div id="sign-in"> element to your HTML --> <div id="sign-in"></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 signInDiv = document.getElementById('sign-in'); Clerk.mountSignIn(signInDiv); // ... Clerk.unmountSignIn(signInDiv); }); </script>
openSignIn()
Opens the <SignIn />
component as an overlay at the root of your HTML body
element.
function openSignIn(props?: SignInProps): void;
openSignIn()
params
Name | Type | Desciption |
---|---|---|
props? | SignInProps | The properties to pass to the <SignIn /> component |
openSignIn()
usage
index.jsimport Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); clerk.openSignIn();
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.openSignIn(); }); </script>
closeSignIn()
Closes the sign in overlay.
function closeSignIn(): void;
closeSignIn()
usage
index.jsimport Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); clerk.openSignIn(); // ... clerk.closeSignIn();
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.openSignIn(); // ... Clerk.closeSignIn(); }); </script>
Customization
To learn about how to customize Clerk components, see the customization documentation.
Last updated on April 15, 2024