Docs

useSignIn()

The useSignIn() hook provides access to the SignIn object, which allows you to check the current state of a sign-in attempt and manage the sign-in flow. You can use this to create a custom sign-in flow.

Returns

  • Name
    isLoaded
    Type
    boolean
    Description
  • Name
    setActive()
    Type
    (params: SetActiveParams) => Promise<void>
    Description

    A function that sets the active session.

  • Name
    signIn
    Type
    SignIn
    Description

    An object that contains the current sign-in attempt status and methods to create a new sign-in attempt.

  • Name
    session
    Type
    Session | string | null
    Description

    The session resource or session ID (string version) to be set as active. If null, the current session is deleted.

  • Name
    organization
    Type
    Organization | string | null
    Description

    The organization resource or organization ID/slug (string version) to be set as active in the current session. If null, the currently active organization is removed as active.

  • Name
    beforeEmit?
    Type
    (session?: Session | null) => void | Promise<any>
    Description

    Callback run just before the active session and/or organization is set to the passed object. Can be used to hook up for pre-navigation actions.

How to use the useSignIn() hook

Check the current state of a sign-in

The following example uses the useSignIn() hook to access the SignIn object, which contains the current sign-in attempt status and methods to create a new sign-in attempt. The isLoaded property is used to handle the loading state.

src/pages/SignInPage.tsx
import { useSignIn } from '@clerk/clerk-react'

export default function SignInPage() {
  const { isLoaded, signIn } = useSignIn()

  if (!isLoaded) {
    // Handle loading state
    return null
  }

  return <div>The current sign-in attempt status is {signIn?.status}.</div>
}

SignIn status values

The status property of the SignIn object can be one of the following values:

  • Name
    complete
    Type
    string
    Description

    The user has been signed in and the custom flow can proceed to setActive() to create a session.

  • Name
    needs_first_factor
    Type
    string
    Description

    One of the following first factor verification strategies is missing: email_link, email_code, phone_code, web3_metamask_signature, web3_coinbase_wallet_signature or oauth_provider.

  • Name
    needs_second_factor
    Type
    string
    Description

    One of the following second factor verification strategies is missing: phone_code or totp.

  • Name
    needs_identifier
    Type
    string
    Description

    The user's identifier (e.g., email address, phone number, username) is missing.

  • Name
    needs_new_password
    Type
    string
    Description

    The user needs to set a new password.

Create a custom sign-in flow with useSignIn()

The useSignIn() hook can also be used to build fully custom sign-in flows, if Clerk's prebuilt components don't meet your specific needs or if you require more control over the authentication flow. Different sign-in flows include email and password, email and phone codes, email links, and multifactor (MFA). To learn more about using the useSignIn() hook to create custom flows, see the custom flow guides.

Feedback

What did you think of this content?

Last updated on