SignIn
The SignIn
object holds all the state of the current sign in and provides helper methods to navigate and complete the sign in process.
There are two important steps in the sign in flow.
- 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 public address or providing proof of their identity through an external social account (SSO/OAuth).
- After that, users might need to go through a second verification process. This is the second factor (2FA).
The SignIn
object's properties can be split into logical groups, with each group providing information on different aspects of the sign in flow. These groups can be:
- Information about the current sign in status in general and which authentication identifiers, authentication methods and verifications are supported.
- Information about the user and the provided authentication identifier value (email address, phone number or username).Information about each verification, either the first factor (logging in) or the second factor (2FA).
Properties
Name | Type | Description |
---|---|---|
status | SignInStatus | The current status of the sign-in.SignInStatus supports the following values:
|
supportedIdentifiers | SignInIdentifier[] | Array of all the authentication identifiers that are supported for this sign in.SignInIdentifier supports the following values:
|
identifier | string | null | The authentication identifier value for the current sign-in. |
supportedFirstFactors | SignInFirstFactor[] | 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. |
supportedSecondFactors | SignInSecondFactor[] | 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. |
firstFactorVerification | Verification | 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. |
secondFactorVerification | Verification | 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 the prepareSecondFactor method in order to start the verification process. For the totp strategy, you can directly attempt. |
userData | UserData | 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. |
createdSessionId | string | null | 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
create()
Use this method to kick-off the sign in flow. It creates a SignIn
object and stores the sign-in lifecycle state.
Depending on the use-case and the params
you pass to the create
method, it can either complete the sign-in process in one go, or simply collect part of the necessary data for completing authentication at a later stage.
function create(params: SignInCreateParams): Promise<SignIn>;
SignInCreateParams
Name | Type | Description |
---|---|---|
identifier | string | The authentication identifier for the sign-in. This can be the value of the user's email address, phone number or username. |
strategy? | string | Select the first factor verification strategy. The strategy value depends on the object's identifier value. Each authentication identifier supports different verification strategies.Possible strategy values are:
|
password? | string | Supply the user's password. This parameter is required only if strategy is set to password . |
ticket? | string | Provide the ticket or token generated from the Backend API. This parameter is required only if strategy is set to ticket . |
redirectUrl? | string | The URL that the OAuth provider should redirect to, on successful authorization on their part. This parameter is required only if strategy is set to an OAuth strategy like oauth_<provider> . If you set the strategy param to email_link , this parameter is optional. |
actionCompleteRedirectUrl? | string | The URL that the user will be redirected to, after successful authorization from the OAuth provider and Clerk sign in. This parameter is required only if strategy is set to an OAuth strategy like oauth_<provider> . |
transfer? | boolean | Transfer the user to a dedicated sign-in for an OAuth flow. |
create()
returns
Type | Description |
---|---|
Promise<SignIn> | This method returns a Promise which resolves with a SignIn object. Check the status attribute to see if the sign-in has been completed or a hint on what needs to happen next. |
resetPassword()
Resets a user's password.
function resetPassword(params: ResetPasswordParams): Promise<SignIn>;
ResetPasswordParams
Name | Type | Description |
---|---|---|
password | string | The user's current password. |
signOutOfOtherSessions? | boolean | undefined | If true , log the user out of all other authenticated sessions. |
resetPassword()
returns
Type | Description |
---|---|
Promise<[SignIn][signin-ref]> | A Promise which resolves with a [SignIn ][signin-ref] object. |
createEmailLinkFlow()
Sets up a sign in with email link flow. Calling createemailLinkFlow()
will return two functions. The first function is async and starts the email link flow, preparing a email link verification. It sends the email link email and starts polling for verification results. The signature is startEmailLinkFlow({ redirectUrl: string, emailAddressId: string }) => Promise<SignInResource>
.
The second function can be used to stop polling at any time, allowing for full control of the flow and cleanup. The signature is cancelEmailLinkFlow() => void
.
function createEmailLinkFlow(): { startEmailLinkFlow: (params: SignInStartEmailLinkFlowParams) => Promise<SignIn>, cancelEmailLinkFlow: () => void }
createEmailLinkFlow()
returns
createEmailLinkFlow
returns an object with two functions:
Name | Type | Description |
---|---|---|
startEmailLinkFlow | (params: SignInStartEmailLinkFlowParams) => Promise<[SignIn][signin-ref]> | Function to start the email link flow. It prepares an email link verification and polls for the verification result. |
cancelEmailLinkFlow | () => void | Function to cleanup the email link flow. Stops waiting for verification results. |
SignInStartEmailLinkFlowParams
Name | Type | Description |
---|---|---|
emailAddressId | string | The ID of the user's email address that's going to be used as the first factor identification for verification. |
redirectUrl | string | The email link target URL. Users will be redirected here once they click the email link from their email. |
Additional methods
In addition to the methods listed above, the SignIn
class also has the following methods:
First factor
Second factor
Authenticate with
Last updated on April 19, 2024