Error handling
Clerk-related errors are returned as an array of ClerkAPIError
objects. These errors contain a code
, message
, longMessage
and meta
property. These properties can be used to provide your users with useful information about the errors being returned from sign-up and sign-in requests.
Example
The following example uses the email & password sign-in custom flow to demonstrate how to handle errors returned during the sign-in process.
This example is written for Next.js App Router but it can be adapted for any React meta framework, such as Remix.
Special error cases
User locked
If you have account lockout enabled on your instance and the user reaches the maximum allowed attempts (see list of relevant actions here), you will receive an HTTP status of 403 (Forbidden)
and the following error payload:
lockout_expires_in_seconds
represents the time remaining until the user is able to attempt authentication again.
In the above example, 1800 seconds (or 30 minutes) are left until they are able to retry, as of the current moment.
The admin might have configured e.g. a 45-minute lockout duration. Thus, 15 minutes after one has been locked, 30 minutes will still remain until the lockout lapses.
You can opt to render the error message returned as-is or format the supplied lockout_expires_in_seconds
value as per your liking in your own custom error message.
For instance, if you wish to inform a user at which absolute time they will be able to try again, you could add the remaining seconds to the current time and format the resulting timestamp.
Feedback
Last updated on