-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clerk-js): Add ability to set active organization by slug (#3825)
Co-authored-by: Izaak Lauer <[email protected]>
- Loading branch information
1 parent
9968994
commit 282ba80
Showing
7 changed files
with
92 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@clerk/clerk-js": patch | ||
"@clerk/types": patch | ||
--- | ||
|
||
Introduce ability to set an active organization by slug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/clerk-js/src/utils/__tests__/organization.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { isOrganizationId } from '../organization'; | ||
|
||
describe('isOrganizationId(string)', () => { | ||
it('should return true for strings starting with `org_`', () => { | ||
expect(isOrganizationId('org_123')).toBe(true); | ||
expect(isOrganizationId('org_abc')).toBe(true); | ||
}); | ||
|
||
it('should return false for strings not starting with `org_`', () => { | ||
expect(isOrganizationId('user_123')).toBe(false); | ||
expect(isOrganizationId('123org_')).toBe(false); | ||
expect(isOrganizationId('ORG_123')).toBe(false); | ||
}); | ||
|
||
it('should handle falsy values', () => { | ||
expect(isOrganizationId(undefined)).toBe(false); | ||
expect(isOrganizationId(null)).toBe(false); | ||
expect(isOrganizationId('')).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Checks and assumes a string is an organization ID if it starts with 'org_', specifically for | ||
* disambiguating with slugs. `_` is a disallowed character in slug names, so slugs cannot | ||
* start with `org_`. | ||
*/ | ||
export function isOrganizationId(id: string | null | undefined): boolean { | ||
return typeof id === 'string' && id.startsWith('org_'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters