Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

<SignIn /> component

Sign in component example

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.

The <SignUp/> and <SignIn/> components cannot render when a user is already signed in, unless the application allows multiple sessions. If a user is already signed in and the application only allows a single session, Clerk will redirect the user to the Home URL instead.

Properties

All props are optional.

NameTypeDescription
appearanceAppearance | undefinedOptional 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' in Next.js and Remix applications. Defaults to hash for all other SDK's.
pathstringThe path where the component is mounted on when routing is set to path. It is ignored in hash- and virtual-based routing.
For example: /sign-in.
signUpUrlstringFull 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.
signInFallbackRedirectUrl?stringThe fallback URL to redirect to after the user signs in, if there's no redirect_url in the path already. Defaults to /. It's recommended to use the environment variable instead.
signInForceRedirectUrl?stringIf provided, this URL will always be redirected to after the user signs in. It's recommended to use the environment variable instead.
initialValuesSignInInitialValuesThe 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.

The following example demonstrates how you can use the <SignIn /> component on a public page.

If you would like to create a dedicated /sign-in page in your Next.js application, check out the dedicated guide..

app/page.tsx
import { SignIn, useUser } from "@clerk/nextjs"; export default function Home() { const { user } = useUser(); if (!user) { return <SignIn />; } return <div>Welcome!</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

NameTypeDescription
nodeHTMLDivElement(opens in a new tab)The container <div> element used to render in the <SignIn /> component
props?SignInPropsThe properties to pass to the <SignIn /> component

mountSignIn() usage

index.js
import 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

NameTypeDescription
nodeHTMLDivElement(opens in a new tab)The container <div> element with a rendered <SignIn /> component instance

unmountSignIn() usage

index.js
import 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

NameTypeDesciption
props?SignInPropsThe properties to pass to the <SignIn /> component

openSignIn() usage

index.js
import 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.js
import 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 24, 2024

What did you think of this content?

Clerk © 2024