SignIn
The SignIn
object holds the state of the current sign-in and provides helper methods to navigate and complete the sign-in process. It is used to manage the sign-in lifecycle, including the first and second factor verification, and the creation of a new session.
The following steps outline the sign-in process:
- Initiate the sign-in process by collecting the user's authentication information and passing the appropriate parameters to the
create()
method. - Prepare the first factor verification by calling
SignIn.prepareFirstFactor()
. Users must complete a first factor verification. This can be something like providing a password, an email link, a one-time code (OTP), a Web3 wallet address, or providing proof of their identity through an external social account (SSO/OAuth). - Attempt to complete the first factor verification by calling
SignIn.attemptFirstFactor()
. - Optionally, if you have enabled multi-factor for your application, you will need to prepare the second factor verification by calling
SignIn.prepareSecondFactor()
. - Attempt to complete the second factor verification by calling
SignIn.attemptSecondFactor()
. - If verification is successful, set the newly created session as the active session by passing the
SignIn.createdSessionId
to thesetActive()
method on theClerk
object.
Properties
- Name
status
- Type
SignInStatus
- Description
The current status of the sign-in.
SignInStatus
supports the following values:'complete'
: The user is signed in and the custom flow can proceed tosetActive()
to create a session.'needs_identifier'
: The user's identifier (e.g., email address, phone number, username) hasn't been provided.'needs_first_factor'
: 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'
.'needs_second_factor'
: One of the following second factor verification strategies is missing:'phone_code'
or'totp'
.'needs_new_password'
: The user needs to set a new password.
- Name
supportedIdentifiers
- Type
SignInIdentifier[]
- Description
Array of all the authentication identifiers that are supported for this sign in.
SignInIdentifier
supports the following values:'email_address'
'phone_number'
'web3_wallet'
'username'
- Name
identifier
- Type
string | null
- Description
Optional if the
strategy
is set to'oauth_<provider>'
or'enterprise_sso'
. Required otherwise. The authentication identifier value for the current sign-in.
- Name
supportedFirstFactors
- Type
SignInFirstFactor[]
- Description
Array of the first factors that are supported in the current sign-in. Each factor contains information about the verification strategy that can be used. See the
SignInFirstFactor
type reference for more information.
- Name
supportedSecondFactors
- Type
SignInSecondFactor[]
- Description
Array of the second factors that are supported in the current sign-in. Each factor contains information about the verification strategy that can be used. This property is populated only when the first factor is verified. See the
SignInSecondFactor
type reference for more information.
- Name
firstFactorVerification
- Type
Verification
- Description
The state of the verification process for the selected first factor. Initially, this property contains an empty verification object, since there is no first factor selected. You need to call the
prepareFirstFactor
method in order to start the verification process.
- Name
secondFactorVerification
- Type
Verification
- Description
The state of the verification process for the selected second factor. Initially, this property contains an empty verification object, since there is no second factor selected. For the
phone_code
strategy, you need to call theprepareSecondFactor
method in order to start the verification process. For thetotp
strategy, you can directly attempt.
- Name
userData
- Type
UserData
- Description
An object containing information about the user of the current sign-in. This property is populated only once an identifier is given to the
SignIn
object.
- Name
createdSessionId
- Type
string | null
- Description
The identifier of the session that was created upon completion of the current sign-in. The value of this property is
null
if the sign-in status is not'complete'
.
Methods
attemptFirstFactor()
Attempts to complete the first factor verification process. This is a required step in order to complete a sign in, as users should be verified at least by one factor of authentication.
Make sure that a SignIn
object already exists before you call this method, either by first calling SignIn.create()
or SignIn.prepareFirstFactor()
. The only strategy that does not require a verification to have already been prepared before attempting to complete it is the password
strategy.
Depending on the strategy that was selected when the verification was prepared, the method parameters will be different.
Returns a SignIn
object. Check the firstFactorVerification
attribute for the status of the first factor verification process.
function attemptFirstFactor(params: AttemptFirstFactorParams): Promise<SignIn>
- Name
strategy
- Type
'email_code' | 'phone_code' | 'password' | 'web3_metamask_signature' | 'web3_coinbase_wallet_signature' | 'web3_okx_wallet_signature' | 'passkey' | 'reset_password_phone_code' | 'reset_password_email_code'
- Description
The
strategy
value depends on theSignIn.identifier
value. Each authentication identifier supports different verification strategies. The following strategies are supported:'email_code'
: User will receive a one-time authentication code via email. At least one email address should be on file for the user.'phone_code'
: User will receive a one-time code via SMS. At least one phone number should be on file for the user.'password'
: The verification will attempt to be completed with the user's password.'web3_metamask_signature'
: The verification will attempt to be completed using the user's Web3 wallet address via Metamask.'web3_coinbase_wallet_signature'
: The verification will attempt to be completed using the user's Web3 wallet address via Coinbase Wallet.'web3_okx_wallet_signature'
: The verification will attempt to be completed using the user's Web3 wallet address via OKX Wallet.'passkey'
: The verification will attempt to be completed using the user's passkey.'reset_password_phone_code'
: Used when the user is trying to reset their password. The user will receive a one-time code via SMS.'reset_password_email_code'
: Used when the user is trying to reset their password. The user will receive a one-time code via email.
- Name
code?
- Type
string
- Description
Required if
strategy
is set to'email_code'
,'phone_code'
,'reset_password_phone_code'
, or'reset_password_email_code'
. The one-time code that was sent to the user.
- Name
password?
- Type
string
- Description
Required if
strategy
is set to'password'
. The user's password string to be verified.
- Name
signature?
- Type
string
- Description
Required if
strategy
is set toweb3_metamask_signature
,web3_coinbase_wallet_signature
, orweb3_okx_wallet_signature
. The Web3 wallet generated signature to be verified.
const signIn = await clerk.signIn.attemptFirstFactor({
strategy: 'email_code',
code: '123456',
})
For comprehensive examples, see the custom flow guides.
attemptSecondFactor()
Attempts to complete the second factor (2FA) verification process, also known as 2FA, or multi-factor authentication.
Returns a SignIn
object. Check the secondFactorVerification
attribute for the status of the second factor verification process.
function attemptSecondFactor(params: AttemptSecondFactorParams): Promise<SignIn>
- Name
strategy
- Type
'phone_code' | 'totp'
- Description
The strategy to be used for second factor verification. Possible
strategy
values are'phone_code'
: User will receive a one-time authentication code via SMS. At least one phone number should be on file for the user.'totp'
: User must provide a 6-digit TOTP code generated by their authenticator app. The user must have previously created a TOTP secret and registered it in their authenticator app using a QR code, URI, or by manually entering the secret.
- Name
code
- Type
string
- Description
- For the
'phone_code'
strategy: The one-time code that was sent to the user as part of theprepareSecondFactor()
step. - For the
'totp'
strategy: The TOTP generated by the user's authenticator app.
- For the
const signIn = await clerk.signIn.attemptSecondFactor({
strategy: 'phone_code',
code: '123456',
})
For a comprehensive example, see the custom flow for multi-factor authentication.
authenticateWithCoinbaseWallet()
Initiates an authentication flow using the Coinbase Wallet browser extension, allowing users to authenticate via their Web3 wallet address. This method prompts the user to connect their Coinbase Wallet and sign a message to verify ownership of the wallet address.
function authenticateWithCoinbaseWallet(): Promise<SignInResource>
const signIn = await clerk.signIn.authenticateWithCoinbaseWallet()
authenticateWithMetamask()
Initiates an authentication flow using the MetaMask browser extension, allowing users to authenticate via their Ethereum wallet address. This method prompts the user to connect their MetaMask wallet and sign a message to verify ownership of the wallet address.
function authenticateWithMetamask(): Promise<SignInResource>
const signIn = await clerk.signIn.authenticateWithMetamask()
authenticateWithOKXWallet()
Initiates an authentication flow using the OKX Wallet browser extension, allowing users to authenticate via their Web3 wallet address. This method prompts the user to connect their OKX Wallet and sign a message to verify ownership of the wallet address.
function authenticateWithOKXWallet(): Promise<SignInResource>
const signIn = await clerk.signIn.authenticateWithOKXWallet()
authenticateWithPasskey()
Initiates a passkey-based authentication flow, enabling users to authenticate using a previously registered passkey. When called without parameters, this method requires a prior call to SignIn.create({ strategy: 'passkey' })
to initialize the sign-in context. This pattern is particularly useful in scenarios where the authentication strategy needs to be determined dynamically at runtime.
function authenticateWithPasskey(params?: AuthenticateWithPasskeyParams): Promise<SignInResource>
AuthenticateWithPasskeyParams
- Name
flow
- Type
'autofill' | 'discoverable'
- Description
The flow to use for the passkey sign-in.
'autofill'
: The client prompts your users to select a passkey before they interact with your app.'discoverable'
: The client requires the user to interact with the client.
const signIn = await clerk.signIn.authenticateWithPasskey({ flow: 'discoverable' })
authenticateWithRedirect()
Signs in a user via a Single Sign On (SSO) connection, such as OAuth or SAML, where an external account is used for verifying the user's identity.
function authenticateWithRedirect(params: AuthenticateWithRedirectParams): Promise<void>
- Name
strategy
- Type
OAuthStrategy | 'saml' | 'enterprise_sso'
- Description
The strategy to use for authentication. The following strategies are supported:
'oauth_<provider>'
: The user will be authenticated with their social connection account. See a list of supported values for<provider>
.'saml'
(deprecated): Deprecated in favor of'enterprise_sso'
. The user will be authenticated with their SAML account.'enterprise_sso'
: The user will be authenticated either through SAML or OIDC depending on the configuration of their enterprise SSO account.
- Name
redirectUrl
- Type
string
- Description
The full URL or path that the OAuth provider should redirect to, on successful authorization on their part. Typically, this will be a simple
/sso-callback
route that callsClerk.handleRedirectCallback
or mounts the<AuthenticateWithRedirectCallback />
component. See the custom flow for implementation details.
- Name
redirectUrlComplete
- Type
string
- Description
The full URL or path that the user will be redirected to once the sign-in is complete.
- Name
identifier
- Type
string | undefined
- Description
- Name
emailAddress
- Type
string | undefined
- Description
The email address used to target an enterprise connection during sign-in.
- Name
legalAccepted
- Type
boolean | undefined
- Description
A boolean indicating whether the user has agreed to the legal compliance documents.
Example
For OAuth connections, see the custom flow for OAuth connections. For enterprise connections, see the custom flow for enterprise connections.
authenticateWithWeb3()
Initiates a Web3 authentication flow by verifying the user's ownership of a blockchain wallet address through cryptographic signature verification. This method enables decentralized authentication without requiring traditional credentials.
function authenticateWithWeb3(params: AuthenticateWithWeb3Params): Promise<SignInResource>
- Name
identifier
- Type
string
- Description
The user's Web3 ID.
- Name
generateSignature
- Type
(opts: GenerateSignatureParams) => Promise<string>
- Description
The method of how to generate the signature for the Web3 sign-in. See
GenerateSignatureParams
for more information.
- Name
strategy?
- Type
Web3Strategy
- Description
The Web3 verification strategy.
GenerateSignatureParams
- Name
identifier
- Type
string
- Description
The user's Web3 wallet address.
- Name
nonce
- Type
string
- Description
The cryptographic nonce used in the sign-in.
- Name
provider?
- Type
Web3Provider
- Description
const signIn = await clerk.signIn.authenticateWithWeb3({
identifier: '0x1234567890123456789012345678901234567890',
})
create()
Creates and returns a new SignIn
instance initialized with the provided parameters. The instance maintains the sign-in lifecycle state through its status
property, which updates as the authentication flow progresses. This method serves as the entry point for initiating a sign-in flow.
What you must pass to params
depends on which sign-in options you have enabled in your app's settings in the Clerk Dashboard.
You can complete the sign-in process in one step if you supply the required fields to create()
. Otherwise, Clerk's sign-in process provides great flexibility and allows users to easily create multi-step sign-in flows.
function create(params: SignInCreateParams): Promise<SignIn>
- Name
strategy?
- Type
'password' | 'email_link' | 'email_code' | 'phone_code' | 'oauth_<provider>' | 'saml' | 'enterprise_sso' | 'passkey' | 'web3_metamask_signature' | 'web3_coinbase_wallet_signature' | 'web3_okx_wallet_signature' | 'ticket' | 'google_one_tap'
- Description
The first factor verification strategy to use in the sign-in flow. Depends on the
SignIn.identifier
value. Each authentication identifier supports different verification strategies. The following strategies are supported:'password'
: The verification will attempt to be completed using the user's password.'email_link'
: User will receive an email magic link via email. Theidentifier
parameter can also be specified to select one of the user's known email addresses. TheredirectUrl
parameter can also be specified.'email_code'
: User will receive a one-time authentication code via email. Theidentifier
parameter can also be specified to select one of the user's known email addresses.'phone_code'
: User will receive a one-time authentication code via SMS. Theidentifier
parameter can also be specified to select one of the user's known phone numbers.'oauth_<provider>'
: The user will be authenticated with their social connection account. See a list of supported values for<provider>
.'saml'
(deprecated): Deprecated in favor of'enterprise_sso'
. The user will be authenticated with their SAML account.'enterprise_sso'
: The user will be authenticated either through SAML or OIDC depending on the configuration of their enterprise SSO account.'passkey'
: The user will be authenticated with their passkey.'web3_metamask_signature'
: The verification will attempt to be completed using the user's Web3 wallet address via Metamask. Theidentifier
parameter can also be specified to select which of the user's known Web3 wallets will be used.'web3_coinbase_wallet_signature'
: The verification will attempt to be completed using the user's Web3 wallet address via Coinbase Wallet. Theidentifier
parameter can also be specified to select which of the user's known Web3 wallets will be used.'web3_okx_wallet_signature'
: The verification will attempt to be completed using the user's Web3 wallet address via OKX Wallet. Theidentifier
parameter can also be specified to select which of the user's known Web3 wallets will be used.'ticket'
: The user will be authenticated via the ticket or token generated from the Backend API.'google_one_tap'
: The user will be authenticated with the Google One Tap UI. It's recommended to useauthenticateWithGoogleOneTap()
instead, as it will also set the user's current session as active for you.
- Name
identifier
- Type
string
- Description
The authentication identifier for the sign-in. This can be the value of the user's email address, phone number, username, or Web3 wallet address.
- Name
password?
- Type
string
- Description
The user's password. Only supported if
strategy
is set to'password'
and password is enabled.
- Name
ticket?
- Type
string
- Description
Required if
strategy
is set to'ticket'
. The ticket or token generated from the Backend API.
- Name
redirectUrl?
- Type
string
- Description
If
strategy
is set to'oauth_<provider>'
or'enterprise_sso'
, this specifies the full URL or path that the OAuth provider should redirect to after successful authorization on their part. Typically, this will be a simple/sso-callback
route that either callsClerk.handleRedirectCallback
or mounts the<AuthenticateWithRedirectCallback />
component. See the custom flow for implementation details.If
strategy
is set to'email_link'
, this specifies the URL that the user will be redirected to when they visit the email link. See the custom flow for implementation details.
- Name
actionCompleteRedirectUrl?
- Type
string
- Description
Optional if
strategy
is set to'oauth_<provider>'
or'enterprise_sso'
. The URL that the user will be redirected to, after successful authorization from the OAuth provider and Clerk sign-in.
- Name
transfer?
- Type
boolean
- Description
When set to
true
, theSignIn
will attempt to retrieve information from the activeSignUp
instance and use it to complete the sign-in process. This is useful when you want to seamlessly transition a user from a sign-up attempt to a sign-in attempt.
- Name
oidcPrompt?
- Type
string
- Description
Optional if
strategy
is set to'oauth_<provider>'
or'enterprise_sso'
. The value to pass to the OIDCprompt
parameter in the generated OAuth redirect URL.
- Name
oidcLoginHint?
- Type
string
- Description
Optional if
strategy
is set to'oauth_<provider>'
or'enterprise_sso'
. The value to pass to the OIDClogin_hint
parameter in the generated OAuth redirect URL.
await clerk.signIn.create({
strategy: 'email_link',
identifier: 'test@example.com',
})
For comprehensive examples, see the custom flow guides.
createEmailLinkFlow()
Creates a flow for authenticating users via email links. This method returns functions for initiating and canceling the email link verification process; see the returns section for more information.
function createEmailLinkFlow(): {
startEmailLinkFlow: (params: SignInStartEmailLinkFlowParams) => Promise<SignIn>
cancelEmailLinkFlow: () => void
}
Returns
createEmailLinkFlow
returns an object with two functions:
- Name
startEmailLinkFlow
- Type
(params: SignInStartEmailLinkFlowParams) => Promise<SignIn>
- Description
Function to start the email link flow. It prepares an email link verification and polls for the verification result.
- Name
cancelEmailLinkFlow
- Type
() => void
- Description
Function to cleanup the email link flow. Stops waiting for verification results.
- Name
emailAddressId
- Type
string
- Description
The ID of the user's email address that's going to be used as the first factor identification for verification.
- Name
redirectUrl
- Type
string
- Description
The full URL that the user will be redirected to when they visit the email link.
const { startEmailLinkFlow, cancelEmailLinkFlow } = clerk.signIn.createEmailLinkFlow()
For a comprehensive example, see the custom flow for email links.
prepareFirstFactor()
Begins the first factor verification process. This is a required step in order to complete a sign in, as users should be verified at least by one factor of authentication.
Common scenarios are one-time code (OTP) or social account (SSO) verification. This is determined by the accepted strategy
parameter values. Each authentication identifier supports different strategies.
Returns a SignIn
object. Check the firstFactorVerification
attribute for the status of the first factor verification process.
function prepareFirstFactor(params: PrepareFirstFactorParams): Promise<SignIn>
- Name
strategy
- Type
'email_link' | 'email_code' | 'phone_code' | 'web3_metamask_signature' | 'web3_coinbase_wallet_signature' | 'web3_okx_wallet_signature' | 'passkey' | 'oauth_<provider>' | 'saml' | 'enterprise_sso' | 'reset_password_phone_code' | 'reset_password_email_code'
- Description
The
strategy
value depends on theSignIn.identifier
value. Each authentication identifier supports different verification strategies. The following strategies are supported:'email_link'
: User will receive an email magic link via email.'email_code'
: User will receive a one-time authentication code via email. RequiresemailAddressId
parameter to be set.'phone_code'
: User will receive a one-time authentication code via SMS. RequiresphoneNumberId
parameter to be set.'web3_metamask_signature'
: The verification will attempt to be completed using the user's Web3 wallet address via Metamask. Requiresweb3WalletId
parameter to be set.'web3_coinbase_wallet_signature'
: The verification will attempt to be completed using the user's Web3 wallet address via Coinbase Wallet. Requiresweb3WalletId
parameter to be set.'web3_okx_wallet_signature'
: The verification will attempt to be completed using the user's Web3 wallet address via OKX Wallet. Requiresweb3WalletId
parameter to be set.'passkey'
: The verification will attempt to be completed using the user's passkey.'oauth_<provider>'
: The user will be authenticated with their social connection account. See a list of supported values for<provider>
.'saml'
(deprecated): Deprecated in favor of'enterprise_sso'
. The user will be authenticated with their SAML account.'enterprise_sso'
: The user will be authenticated either through SAML or OIDC depending on the configuration of their enterprise SSO account.'reset_password_phone_code'
: Used when the user is trying to reset their password. The user will receive a one-time code via SMS. RequiresphoneNumberId
parameter to be set.'reset_password_email_code'
: Used when the user is trying to reset their password. The user will receive a one-time code via email. RequiresemailAddressId
parameter to be set.
- Name
emailAddressId?
- Type
string
- Description
Required if
strategy
is set to'email_code'
or'reset_password_email_code'
. The ID for the user's email address that will receive an email with the one-time authentication code.
- Name
phoneNumberId?
- Type
string
- Description
Required if
strategy
is set to'phone_code'
or'reset_password_phone_code'
. The ID for the user's phone number that will receive an SMS message with the one-time authentication code.
- Name
web3WalletId?
- Type
string
- Description
Required if
strategy
is set to'web3_metamask_signature'
,'web3_coinbase_wallet_signature'
, or'web3_okx_wallet_signature'
. The ID for the user's Web3 wallet address.
- Name
redirectUrl?
- Type
string
- Description
Required if
strategy
is set to'oauth_<provider>'
or'enterprise_sso'
. The full URL or path that the OAuth provider should redirect to after successful authorization on their part. Typically, this will be a simple/sso-callback
route that either callsClerk.handleRedirectCallback()
or mounts the<AuthenticateWithRedirectCallback />
component. See the custom flow for implementation details.Required if
strategy
is set to'email_link'
. The full URL that the user will be redirected to when they visit the email link. See the custom flow for implementation details.
- Name
actionCompleteRedirectUrl?
- Type
string
- Description
Required if
strategy
is set to'oauth_<provider>'
or'enterprise_sso'
. The URL that the user will be redirected to once the first factor verification is complete.
const signIn = await clerk.signIn.prepareFirstFactor({
strategy: 'email_link',
identifier: 'test@example.com',
})
For comprehensive examples, see the custom flow guides.
prepareSecondFactor()
Begins the second factor (2FA) verification process. Clerk calls this multi-factor authentication (MFA).
Returns a SignIn
object. Check the secondFactorVerification
attribute for the status of the second factor verification process.
function prepareSecondFactor(params: PrepareSecondFactorParams): Promise<SignIn>
- Name
strategy
- Type
'phone_code'
- Description
The strategy used for second factor verification. Supported strategies are:
'phone_code'
: User will receive a one-time authentication code via SMS. At least one phone number should be on file for the user.
- Name
phoneNumberId
- Type
string
- Description
The ID for the user's phone number that will receive an SMS message with the one-time authentication code.
const signIn = await clerk.signIn.prepareSecondFactor({
strategy: 'phone_code',
phoneNumberId: '123',
})
For a comprehensive example, see the custom flow for multi-factor authentication.
resetPassword()
Resets a user's password.
function resetPassword(params: ResetPasswordParams): Promise<SignIn>
- Name
password
- Type
string
- Description
The user's current password.
- Name
signOutOfOtherSessions?
- Type
boolean | undefined
- Description
If
true
, log the user out of all other authenticated sessions.
await clerk.signIn.resetPassword({
password: 'new-password',
})
Feedback
Last updated on