Repository navigation
Keep lockoutExpiresInSeconds on user_locked ClerkAPIError meta #10357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/shared': patch | ||
| --- | ||
|
|
||
| Keep `meta.lockout_expires_in_seconds` on `user_locked` ClerkAPIError objects so apps can show when the lockout ends. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { ClerkAPIError } from '../errors/clerkApiError'; | ||
| import { errorToJSON } from '../errors/parseError'; | ||
| import type { ClerkAPIErrorJSON } from '../types/errors'; | ||
|
|
||
| describe('user_locked error meta', () => { | ||
| const json: ClerkAPIErrorJSON = { | ||
| code: 'user_locked', | ||
| message: 'Account locked', | ||
| long_message: 'Too many failed attempts. Try again later.', | ||
| meta: { | ||
| lockout_expires_in_seconds: 3599, | ||
| }, | ||
| }; | ||
|
|
||
| it('keeps lockoutExpiresInSeconds from the wire payload', () => { | ||
| const error = new ClerkAPIError(json); | ||
| expect(error.meta.lockoutExpiresInSeconds).toBe(3599); | ||
| }); | ||
|
|
||
| it('survives a snapshot round trip', () => { | ||
| const roundTripped = new ClerkAPIError(errorToJSON(new ClerkAPIError(json))); | ||
| expect(roundTripped.meta.lockoutExpiresInSeconds).toBe(3599); | ||
| expect(errorToJSON(roundTripped).meta?.lockout_expires_in_seconds).toBe(3599); | ||
| }); | ||
|
|
||
| it('leaves an error without lockout duration alone', () => { | ||
| const error = new ClerkAPIError({ | ||
| code: 'form_code_incorrect', | ||
| message: 'Incorrect code', | ||
| meta: { param_name: 'code' }, | ||
| }); | ||
| expect(error.meta.lockoutExpiresInSeconds).toBeUndefined(); | ||
| expect(errorToJSON(error).meta?.lockout_expires_in_seconds).toBeUndefined(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ export interface ClerkAPIErrorJSON { | |
| link_url?: string; | ||
| link_text?: string; | ||
| data?: Record<string, string | number | boolean>; | ||
| lockout_expires_in_seconds?: number; | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -122,6 +123,11 @@ export interface ClerkAPIError { | |
| * sensitive. | ||
| */ | ||
| data?: Record<string, string | number | boolean>; | ||
| /** | ||
| * Seconds until a `user_locked` account can try again. Taken from | ||
| * `meta.lockout_expires_in_seconds` on the API error. | ||
| */ | ||
| lockoutExpiresInSeconds?: number; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Update the Frontend error-handling documentation. The guide in 🤖 Prompt for AI AgentsSource: Linked repositories |
||
| }; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Name the exposed property in the changeset.
ClerkAPIErrorexposesmeta.lockoutExpiresInSeconds, notmeta.lockout_expires_in_seconds. The current note directs readers to the wire-format name. Replace it with the property name that applications can read.🧰 Tools
🪛 markdownlint-cli2 (0.23.3)
[warning] 5-5: First line in a file should be a top-level heading
(MD041, first-line-heading, first-line-h1)
🤖 Prompt for AI Agents