Skip to content
Open
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
8 changes: 8 additions & 0 deletions .changeset/calm-maps-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@clerk/localizations': minor
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/ui': minor
---

Surface organization creation defaults with prefilled form fields and advisory warnings
4 changes: 2 additions & 2 deletions packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"files": [
{ "path": "./dist/clerk.js", "maxSize": "538KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "63KB" },
{ "path": "./dist/clerk.chips.browser.js", "maxSize": "63KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "66KB" },
{ "path": "./dist/clerk.chips.browser.js", "maxSize": "66KB" },
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "105KB" },
{ "path": "./dist/clerk.no-rhc.js", "maxSize": "305KB" },
{ "path": "./dist/clerk.headless*.js", "maxSize": "65KB" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import type {
OrganizationCreationAdvisorySeverity,
OrganizationCreationAdvisoryType,
OrganizationCreationDefaultsJSON,
OrganizationCreationDefaultsJSONSnapshot,
OrganizationCreationDefaultsResource,
} from '@clerk/shared/types';

import { BaseResource } from './internal';

export class OrganizationCreationDefaults extends BaseResource implements OrganizationCreationDefaultsResource {
advisory: {
code: OrganizationCreationAdvisoryType;
severity: OrganizationCreationAdvisorySeverity;
meta: Record<string, string>;
} | null = null;
form: {
name: string;
slug: string;
logo: string | null;
blurHash: string | null;
} = {
name: '',
slug: '',
logo: null,
blurHash: null,
};

public constructor(data: OrganizationCreationDefaultsJSON | OrganizationCreationDefaultsJSONSnapshot | null = null) {
super();
this.fromJSON(data);
}

protected fromJSON(data: OrganizationCreationDefaultsJSON | OrganizationCreationDefaultsJSONSnapshot | null): this {
if (!data) {
return this;
}

if (data.advisory) {
this.advisory = this.withDefault(data.advisory, this.advisory ?? null);
}

if (data.form) {
this.form.name = this.withDefault(data.form.name, this.form.name);
this.form.slug = this.withDefault(data.form.slug, this.form.slug);
this.form.logo = this.withDefault(data.form.logo, this.form.logo);
this.form.blurHash = this.withDefault(data.form.blur_hash, this.form.blurHash);
}

return this;
}

static async retrieve(): Promise<OrganizationCreationDefaultsResource> {
return await BaseResource._fetch({
path: '/me/organization_creation_defaults',
method: 'GET',
}).then(res => {
const data = res?.response as unknown as OrganizationCreationDefaultsJSON;
return new OrganizationCreationDefaults(data);
});
}
Comment on lines +53 to +61
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Unsafe type casting bypasses validation and could cause runtime errors.

Line 55 uses as unknown as OrganizationCreationDefaultsJSON to force-cast the API response without any validation. If the API returns malformed data or the response structure changes, this will bypass type safety and could cause runtime errors when the resource properties are accessed.

🔎 Proposed fix with runtime validation
   static async retrieve(): Promise<OrganizationCreationDefaultsResource> {
     return await BaseResource._fetch({
       path: '/me/organization_creation_defaults',
       method: 'GET',
     }).then(res => {
-      const data = res?.response as unknown as OrganizationCreationDefaultsJSON;
+      const data = res?.response;
+      // Basic runtime validation
+      if (!data || typeof data !== 'object') {
+        throw new Error('Invalid organization creation defaults response');
+      }
       return new OrganizationCreationDefaults(data);
     });
   }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/clerk-js/src/core/resources/OrganizationCreationDefaults.ts around
lines 50 to 58, the code force-casts the API response using "as unknown as
OrganizationCreationDefaultsJSON" which bypasses runtime validation; replace the
cast with a proper runtime check: extract res.response, validate required fields
and types (either with a small type-guard function or an existing JSON/schema
validator), throw or return a clear error if validation fails, and only then
construct and return new OrganizationCreationDefaults(validatedData); do not use
"as unknown as" to silence type checking.


public __internal_toSnapshot(): OrganizationCreationDefaultsJSONSnapshot {
return {
advisory: this.advisory
? {
code: this.advisory.code,
meta: this.advisory.meta,
severity: this.advisory.severity,
}
: null,
form: {
name: this.form.name,
slug: this.form.slug,
logo: this.form.logo,
blur_hash: this.form.blurHash,
},
} as unknown as OrganizationCreationDefaultsJSONSnapshot;
}
}
12 changes: 12 additions & 0 deletions packages/clerk-js/src/core/resources/OrganizationSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export class OrganizationSettings extends BaseResource implements OrganizationSe
} = {
disabled: false,
};
organizationCreationDefaults: {
enabled: boolean;
} = {
enabled: false,
};
enabled: boolean = false;
maxAllowedMemberships: number = 1;
forceOrganizationSelection!: boolean;
Expand Down Expand Up @@ -51,6 +56,13 @@ export class OrganizationSettings extends BaseResource implements OrganizationSe
this.slug.disabled = this.withDefault(data.slug.disabled, this.slug.disabled);
}

if (data.organization_creation_defaults) {
this.organizationCreationDefaults.enabled = this.withDefault(
data.organization_creation_defaults.enabled,
this.organizationCreationDefaults.enabled,
);
}

this.enabled = this.withDefault(data.enabled, this.enabled);
this.maxAllowedMemberships = this.withDefault(data.max_allowed_memberships, this.maxAllowedMemberships);
this.forceOrganizationSelection = this.withDefault(
Expand Down
3 changes: 3 additions & 0 deletions packages/clerk-js/src/core/resources/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
UserOrganizationInvitation,
Web3Wallet,
} from './internal';
import { OrganizationCreationDefaults } from './OrganizationCreationDefaults';

export class User extends BaseResource implements UserResource {
pathRoot = '/me';
Expand Down Expand Up @@ -275,6 +276,8 @@ export class User extends BaseResource implements UserResource {
getOrganizationMemberships: GetOrganizationMemberships = retrieveMembership =>
OrganizationMembership.retrieve(retrieveMembership);

getOrganizationCreationDefaults = () => OrganizationCreationDefaults.retrieve();

leaveOrganization = async (organizationId: string): Promise<DeletedObjectResource> => {
const json = (
await BaseResource._fetch<DeletedObjectJSON>({
Expand Down
4 changes: 4 additions & 0 deletions packages/clerk-js/src/test/fixture-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ const createOrganizationSettingsFixtureHelpers = (environment: EnvironmentJSON)
const withOrganizationSlug = (enabled = false) => {
os.slug.disabled = !enabled;
};
const withOrganizationCreationDefaults = (enabled = false) => {
os.organization_creation_defaults.enabled = enabled;
};

const withOrganizationDomains = (modes?: OrganizationEnrollmentMode[], defaultRole?: string) => {
os.domains.enabled = true;
Expand All @@ -356,6 +359,7 @@ const createOrganizationSettingsFixtureHelpers = (environment: EnvironmentJSON)
withOrganizationDomains,
withForceOrganizationSelection,
withOrganizationSlug,
withOrganizationCreationDefaults,
};
};

Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/ar-SA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,10 @@ export const arSA: LocalizationResource = {
actionLink: 'تسجيل الخروج',
actionText: 'تم تسجيل الدخول كـ {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'توجد منظمة بالفعل لاسم الشركة المكتشف ({{organizationName}}) و {{organizationDomain}}. انضم عن طريق الدعوة.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/be-BY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,10 @@ export const beBY: LocalizationResource = {
actionLink: 'Выйсці',
actionText: 'Увайшлі як {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Арганізацыя ўжо існуе для выяўленай назвы кампаніі ({{organizationName}}) і {{organizationDomain}}. Далучайцеся па запрашэнні.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/bg-BG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,10 @@ export const bgBG: LocalizationResource = {
actionLink: 'Изход',
actionText: 'Влязъл като {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Организация вече съществува за откритото име на компанията ({{organizationName}}) и {{organizationDomain}}. Присъединете се чрез покана.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/bn-IN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,10 @@ export const bnIN: LocalizationResource = {
actionLink: 'সাইন আউট',
actionText: '{{identifier}} হিসাবে সাইন ইন করা হয়েছে',
},
alerts: {
organizationAlreadyExists:
'শনাক্ত করা কোম্পানির নাম ({{organizationName}}) এবং {{organizationDomain}}-এর জন্য একটি সংস্থা ইতিমধ্যেই বিদ্যমান। আমন্ত্রণের মাধ্যমে যোগ দিন।',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/ca-ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,10 @@ export const caES: LocalizationResource = {
actionLink: 'Tancar sessió',
actionText: 'Sessió iniciada com a {{identifier}}',
},
alerts: {
organizationAlreadyExists:
"Ja existeix una organització per al nom d'empresa detectat ({{organizationName}}) i {{organizationDomain}}. Uneix-te per invitació.",
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/cs-CZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,10 @@ export const csCZ: LocalizationResource = {
actionLink: 'Odhlásit se',
actionText: 'Přihlášen jako {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Organizace již existuje pro detekovaný název společnosti ({{organizationName}}) a {{organizationDomain}}. Připojte se prostřednictvím pozvánky.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/da-DK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,10 @@ export const daDK: LocalizationResource = {
actionLink: 'Log ud',
actionText: 'Logget ind som {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Der findes allerede en organisation for det registrerede firmanavn ({{organizationName}}) og {{organizationDomain}}. Tilmeld dig via invitation.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/de-DE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,10 @@ export const deDE: LocalizationResource = {
actionLink: 'Abmelden',
actionText: 'Angemeldet als {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Für den erkannten Firmennamen ({{organizationName}}) und {{organizationDomain}} existiert bereits eine Organisation. Treten Sie per Einladung bei.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/el-GR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ export const elGR: LocalizationResource = {
actionLink: 'Αποσύνδεση',
actionText: 'Συνδεδεμένος ως {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Υπάρχει ήδη οργανισμός για το ανιχνευμένο όνομα εταιρείας ({{organizationName}}) και {{organizationDomain}}. Εγγραφείτε μέσω πρόσκλησης.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/en-GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,10 @@ export const enGB: LocalizationResource = {
actionLink: 'Sign out',
actionText: 'Signed in as {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'An organisation already exists for the detected company name ({{organizationName}}) and {{organizationDomain}}. Join by invitation.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,10 @@ export const enUS: LocalizationResource = {
actionLink: 'Sign out',
actionText: 'Signed in as {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'An organization already exists for the detected company name ({{organizationName}}) and {{organizationDomain}}. Join by invitation.',
},
},
taskResetPassword: {
formButtonPrimary: 'Reset Password',
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/es-CR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,10 @@ export const esCR: LocalizationResource = {
actionLink: 'Cerrar sesión',
actionText: 'Conectado como {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Ya existe una organización para el nombre de empresa detectado ({{organizationName}}) y {{organizationDomain}}. Únete por invitación.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/es-ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,10 @@ export const esES: LocalizationResource = {
actionLink: 'Cerrar sesión',
actionText: 'Sesión iniciada como {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Ya existe una organización para el nombre de empresa detectado ({{organizationName}}) y {{organizationDomain}}. Únete por invitación.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/es-MX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,10 @@ export const esMX: LocalizationResource = {
actionLink: 'Cerrar sesión',
actionText: 'Registrado como {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Ya existe una organización para el nombre de empresa detectado ({{organizationName}}) y {{organizationDomain}}. Únete por invitación.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/es-UY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,10 @@ export const esUY: LocalizationResource = {
actionLink: 'Cerrar sesión',
actionText: 'Logueado como {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Ya existe una organización para el nombre de empresa detectado ({{organizationName}}) y {{organizationDomain}}. Únete por invitación.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/fa-IR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,10 @@ export const faIR: LocalizationResource = {
actionLink: 'خروج از همه حساب‌ها',
actionText: 'می‌خواهید خارج شوید؟',
},
alerts: {
organizationAlreadyExists:
'سازمانی برای نام شرکت شناسایی شده ({{organizationName}}) و {{organizationDomain}} از قبل وجود دارد. از طریق دعوتنامه بپیوندید.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/fi-FI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,10 @@ export const fiFI: LocalizationResource = {
actionLink: 'Kirjaudu ulos',
actionText: 'Kirjautuneena käyttäjänä {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Organisaatio on jo olemassa havaitulle yrityksen nimelle ({{organizationName}}) ja {{organizationDomain}}. Liity kutsulla.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/fr-FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,10 @@ export const frFR: LocalizationResource = {
actionLink: 'Se déconnecter',
actionText: 'Connecté en tant que {{identifier}}',
},
alerts: {
organizationAlreadyExists:
"Une organisation existe déjà pour le nom d'entreprise détecté ({{organizationName}}) et {{organizationDomain}}. Rejoignez par invitation.",
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/he-IL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,10 @@ export const heIL: LocalizationResource = {
actionLink: 'התנתק',
actionText: 'מחובר כ-{{identifier}}',
},
alerts: {
organizationAlreadyExists:
'ארגון כבר קיים עבור שם החברה שזוהה ({{organizationName}}) ו-{{organizationDomain}}. הצטרף באמצעות הזמנה.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/hi-IN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,10 @@ export const hiIN: LocalizationResource = {
actionLink: 'साइन आउट',
actionText: '{{identifier}} के रूप में साइन इन किया गया',
},
alerts: {
organizationAlreadyExists:
'पता लगाई गई कंपनी के नाम ({{organizationName}}) और {{organizationDomain}} के लिए एक संगठन पहले से मौजूद है। आमंत्रण द्वारा शामिल हों।',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
4 changes: 4 additions & 0 deletions packages/localizations/src/hr-HR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,10 @@ export const hrHR: LocalizationResource = {
actionLink: 'Odjavi se',
actionText: 'Prijavljen kao {{identifier}}',
},
alerts: {
organizationAlreadyExists:
'Organizacija već postoji za otkriveni naziv tvrtke ({{organizationName}}) i {{organizationDomain}}. Pridružite se putem pozivnice.',
},
},
taskResetPassword: {
formButtonPrimary: undefined,
Expand Down
Loading
Loading