-
Notifications
You must be signed in to change notification settings - Fork 359
chore(types,clerk-react,astro,vue): Share Protect component prop type between SDKs #6197
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3fd9963
chore: Shared Protect component types
wobsoriano 687104f
chore: add changeset
wobsoriano 17d7329
Merge branch 'main' into rob/shared-protect-props
wobsoriano 49b289a
Merge branch 'main' into rob/shared-protect-props
wobsoriano 52bb9b3
Merge branch 'main' into rob/shared-protect-props
wobsoriano 03e46ef
chore: add jsdoc to type
wobsoriano 527a9b4
fix typedoc
wobsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
--- | ||
"@clerk/astro": patch | ||
"@clerk/clerk-react": patch | ||
"@clerk/types": patch | ||
"@clerk/vue": patch | ||
--- | ||
|
||
Extract internal `ProtectProps` type to shared types to eliminate duplication across SDKs |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,70 @@ | ||
import type { OrganizationCustomPermissionKey, OrganizationCustomRoleKey } from './organizationMembership'; | ||
import type { CheckAuthorizationWithCustomPermissions } from './session'; | ||
import type { Autocomplete } from './utils'; | ||
|
||
/** | ||
* Props for the `<Protect />` component, which restricts access to its children based on authentication and authorization. | ||
* | ||
* Use `ProtectProps` to specify the required role, permission, feature, or plan for access. | ||
* | ||
* @example | ||
* ```tsx | ||
* // Require a specific permission | ||
* <Protect permission="a_permission_key" /> | ||
* | ||
* // Require a specific role | ||
* <Protect role="a_role_key" /> | ||
* | ||
* // Use a custom condition callback | ||
* <Protect condition={(has) => has({ permission: "a_permission_key" })} /> | ||
* | ||
* // Require a specific feature | ||
* <Protect feature="a_feature_key" /> | ||
* | ||
* // Require a specific plan | ||
* <Protect plan=a_plan_key" /> | ||
* ``` | ||
*/ | ||
export type ProtectProps = | ||
| { | ||
condition?: never; | ||
role: OrganizationCustomRoleKey; | ||
permission?: never; | ||
feature?: never; | ||
plan?: never; | ||
} | ||
| { | ||
condition?: never; | ||
role?: never; | ||
feature?: never; | ||
plan?: never; | ||
permission: OrganizationCustomPermissionKey; | ||
} | ||
| { | ||
condition: (has: CheckAuthorizationWithCustomPermissions) => boolean; | ||
role?: never; | ||
permission?: never; | ||
feature?: never; | ||
plan?: never; | ||
} | ||
| { | ||
condition?: never; | ||
role?: never; | ||
permission?: never; | ||
feature: Autocomplete<`user:${string}` | `org:${string}`>; | ||
plan?: never; | ||
} | ||
| { | ||
condition?: never; | ||
role?: never; | ||
permission?: never; | ||
feature?: never; | ||
plan: Autocomplete<`user:${string}` | `org:${string}`>; | ||
} | ||
| { | ||
condition?: never; | ||
role?: never; | ||
permission?: never; | ||
feature?: never; | ||
plan?: never; | ||
}; | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.