Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
feat(ui,clerk-js,shared): Surface organization creation defaults#7488
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e401daa700303b15c847008831070c0b9556a3125a0aa3266f6b80b9b420efe8a0e4696d3189d51300f16b2fd4087d56ea437ada9988a6dace1d552File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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); | ||
| }); | ||
| } | ||
| 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; | ||
| } | ||
LauraBeatris marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -884,6 +884,10 @@ export const enUS: LocalizationResource = { | ||
| actionLink: 'Sign out', | ||
| actionText: 'Signed in as {{identifier}}', | ||
| }, | ||
| alerts: { | ||
| organizationAlreadyExists: | ||
LauraBeatris marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 'An organization already exists for the detected company name ({{organizationName}}) and {{organizationDomain}}. Join by invitation.', | ||
| }, | ||
| }, | ||
| taskResetPassword: { | ||
| formButtonPrimary: 'Reset Password', | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Unsafe type casting bypasses validation and could cause runtime errors.
Line 55 uses
as unknown as OrganizationCreationDefaultsJSONto 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); }); }🤖 Prompt for AI Agents