Skip to content

fix(clerk-js): Pass metadata as variables for error localization #6167

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twenty-games-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Pass the metadata as variables for error localization
8 changes: 5 additions & 3 deletions packages/clerk-js/src/ui/localization/makeLocalizable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ export const useLocalizations = () => {
}

const { code, message, longMessage, meta } = (error || {}) as ClerkAPIError;
const { paramName = '' } = meta || {};
const { paramName = '', identifiers, emailAddresses } = meta || {};
Copy link
Member

@tmilewski tmilewski Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the example, not_allowed_access: '{{identifiers}} is not allowed to access this page!!!!!' - would this be confusing there are multiple identifiers (or emailsAddresses) returned.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are always arrays with 1 or more items.

Yes, the error message needs to be agnostic on the "is"/"are" part.


if (!code) {
return '';
}

const metaArgsAsVariables = { identifiers: identifiers?.join(', '), emailAddresses: emailAddresses?.join(', ') };

return (
t(localizationKeys(`unstable__errors.${code}__${paramName}` as any)) ||
t(localizationKeys(`unstable__errors.${code}` as any)) ||
t(localizationKeys(`unstable__errors.${code}__${paramName}` as any, metaArgsAsVariables)) ||
t(localizationKeys(`unstable__errors.${code}` as any, metaArgsAsVariables)) ||
longMessage ||
message
);
Expand Down
Loading