Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce internal Gate component #1834

Merged
merged 2 commits into from
Oct 9, 2023
Merged

Introduce internal Gate component #1834

merged 2 commits into from
Oct 9, 2023

Conversation

panteliselef
Copy link
Member

@panteliselef panteliselef commented Oct 5, 2023

Description

This PR

  • Introduces a new method isAuthorized in the Session class. Returns a promise (future proofing) and checks whether the active user is allowed to perform an action based on the passed (required) permission and the ones attached to the membership.
  • Introduces an internal Gate component (supporting hook and HOC) which enables us to conditionally render parts of our components based on a users permissions. (it will replace all isAdmin checks)

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 馃悰 Bug fix
  • 馃専 New feature
  • 馃敤 Breaking change
  • 馃摉 Refactoring / dependency upgrade / documentation
  • other:

Packages affected

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/remix
  • @clerk/types
  • @clerk/themes
  • @clerk/localizations
  • @clerk/clerk-expo
  • @clerk/backend
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/fastify
  • @clerk/chrome-extension
  • gatsby-plugin-clerk
  • build/tooling/chore

@panteliselef panteliselef self-assigned this Oct 5, 2023
@panteliselef panteliselef requested a review from a team as a code owner October 5, 2023 20:10
@changeset-bot
Copy link

changeset-bot bot commented Oct 5, 2023

馃 Changeset detected

Latest commit: 3c1a648

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@clerk/clerk-js Patch
@clerk/types Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/backend Patch
@clerk/fastify Patch
gatsby-plugin-clerk Patch
@clerk/localizations Patch
@clerk/nextjs Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -18,6 +19,8 @@ export class OrganizationMembership extends BaseResource implements Organization
publicMetadata: OrganizationMembershipPublicMetadata = {};
publicUserData!: PublicUserData;
organization!: Organization;
// eslint-disable-next-line
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: adding (string & {}) allows for getting eslint autocomplete but also accepts any string

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we write this in a comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

good call

if (domain) {
setData({ ...domain });
callbacks?.onSuccess?.({ ...domain });
if (typeof result !== 'undefined') {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note for reviewer: if value is an object then do a shallow copy otherwise use the actual value

@panteliselef panteliselef changed the title [WIP] Introduce internal Gate component Introduce internal Gate component Oct 6, 2023
'@clerk/types': patch
---

Introduces a new method isAuthorized in the Session class. Returns a promise and checks whether the active user is allowed to perform an action based on the passed (required) permission and the ones attached to the membership.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Introduces a new method isAuthorized in the Session class. Returns a promise and checks whether the active user is allowed to perform an action based on the passed (required) permission and the ones attached to the membership.
Introduces a new `isAuthorized()` method in the `Session` class. Returns a promise and checks whether the active user is allowed to perform an action based on the passed (required) permission and the ones attached to the membership.

'@clerk/clerk-js': patch
---

Introduces an internal Gate component (supporting hook and HOC) which enables us to conditionally render parts of our components based on a users permissions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Introduces an internal Gate component (supporting hook and HOC) which enables us to conditionally render parts of our components based on a users permissions.
Introduces an internal `<Gate/>` component (supporting hook and HOC) which enables us to conditionally render parts of our components based on a users permissions.

Copy link
Member

@chanioxaris chanioxaris left a comment

Choose a reason for hiding this comment

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

Let's mark any new permission related types and functions as experimental for now

@panteliselef panteliselef added this pull request to the merge queue Oct 9, 2023
Merged via the queue into main with commit 997b8e2 Oct 9, 2023
6 checks passed
@panteliselef panteliselef deleted the ORG-248 branch October 9, 2023 10:37
@clerk-cookie clerk-cookie mentioned this pull request Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants