-
Notifications
You must be signed in to change notification settings - Fork 422
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
base: main
Are you sure you want to change the base?
Changes from all commits
f83526b
8155783
3751b00
928ef24
47b4a85
1c9e668
7c9d1ec
aedae26
2648851
fd12f1c
22c5fce
3a076b0
6589db1
5611bb5
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,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,74 @@ | ||
| 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, | ||
| } as unknown as OrganizationCreationDefaultsJSONSnapshot; | ||
| } | ||
|
Comment on lines
+63
to
+73
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. Incomplete snapshot: missing The 🐛 Proposed fix public __internal_toSnapshot(): OrganizationCreationDefaultsJSONSnapshot {
return {
advisory: this.advisory
? {
code: this.advisory.code,
meta: this.advisory.meta,
severity: this.advisory.severity,
}
: null,
- } as unknown as OrganizationCreationDefaultsJSONSnapshot;
+ form: {
+ name: this.form.name,
+ slug: this.form.slug,
+ logo: this.form.logo,
+ blur_hash: this.form.blurHash,
+ },
+ };
}🤖 Prompt for AI Agents |
||
| } | ||
| 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: | ||
|
Member
Author
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. Let's also include the company name:
|
||
| 'An organization already exists for the detected company name and {{email}}. Join by invitation.', | ||
| }, | ||
| }, | ||
| taskResetPassword: { | ||
| formButtonPrimary: 'Reset Password', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { ClerkResourceJSON } from './json'; | ||
| import type { ClerkResource } from './resource'; | ||
|
|
||
| export type OrganizationCreationAdvisoryType = 'organization_already_exists'; | ||
|
|
||
| export type OrganizationCreationAdvisorySeverity = 'warning'; | ||
|
|
||
| export interface OrganizationCreationDefaultsJSON extends ClerkResourceJSON { | ||
| advisory: { | ||
| code: OrganizationCreationAdvisoryType; | ||
| severity: OrganizationCreationAdvisorySeverity; | ||
| meta: Record<string, string>; | ||
| } | null; | ||
| form: { | ||
| name: string; | ||
| slug: string; | ||
| logo: string | null; | ||
| blur_hash: string | null; | ||
| }; | ||
| } | ||
|
|
||
| export interface OrganizationCreationDefaultsResource extends ClerkResource { | ||
| advisory: { | ||
| code: OrganizationCreationAdvisoryType; | ||
| severity: OrganizationCreationAdvisorySeverity; | ||
| meta: Record<string, string>; | ||
| } | null; | ||
| form: { | ||
| name: string; | ||
| slug: string; | ||
| logo: string | null; | ||
| blurHash: string | null; | ||
| }; | ||
| } |
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