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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add organizationSyncOptions prop to clerkMiddleware() options #1634

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

izaaklauer
Copy link
Contributor

@izaaklauer izaaklauer commented Oct 17, 2024

Depends on the release of clerk/javascript#4320

Preview

https://clerk.com/docs/pr/1634/references/nextjs/clerk-middleware#clerk-middleware-next-js

What changed?

This PR documents a new middleware option introduced in clerk/javascript#3977

What's next?

  • Public DX guide
  • Public changelog entry

@izaaklauer izaaklauer requested a review from a team as a code owner October 17, 2024 20:14
Comment on lines 346 to 377
- `signInUrl?`
- `publishableKey`
- `string`

An alternative sign in URL.
The Clerk publishable key for your instance. This can be found in your Clerk Dashboard on the **[API Keys](https://dashboard.clerk.com/last-active?path=api-keys)** page.

---

- `signUpUrl?`
- `secretKey?`
- `string`

An alternative sign up URL.
The Clerk secret key for your instance. This can be found in your Clerk Dashboard on the **[API Keys](https://dashboard.clerk.com/last-active?path=api-keys)** page. The `CLERK_ENCRYPTION_KEY` environment variable must be set when providing `secretKey` as an option, refer to [Dynamic keys](#dynamic-keys).

---

- `publishableKey`
- `signInUrl?`
- `string`

The Clerk publishable key for your instance. This can be found in your Clerk Dashboard on the **[API Keys](https://dashboard.clerk.com/last-active?path=api-keys)** page.
An alternative sign in URL.

---

- `secretKey?`
- `signUpUrl?`
- `string`

The Clerk secret key for your instance. This can be found in your Clerk Dashboard on the **[API Keys](https://dashboard.clerk.com/last-active?path=api-keys)** page. The `CLERK_ENCRYPTION_KEY` environment variable must be set when providing `secretKey` as an option, refer to [Dynamic keys](#dynamic-keys).
An alternative sign up URL.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is all just a re-arrangement - I noticed that the list was almost alphabetized, and now it's alphabetized.

URL patterns that are organization-specific and contain an organization ID or slug as a path parameter. If a request
matches this path, the organization identifier will be extracted and activated before rendering.

If the route also matches the personalAccountPatterns, this takes precedence.
Copy link
Member

Choose a reason for hiding this comment

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

🔧 Can we have personalAccountPatterns appear with in-line code formatting, or even link to the definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

I don't see a precedent or a way to link to properties, but I can do the code formatting!

ff0d75e

docs/references/nextjs/clerk-middleware.mdx Outdated Show resolved Hide resolved
Comment on lines 467 to 469
> no change will be made to the previously active organization. Components must detect this case and respond with an
> appropriate error (e. g., `notFound()`, an
> [organization switcher](/docs/components/organization/organization-switcher), etc.).
Copy link
Member

Choose a reason for hiding this comment

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

🔧 This sentence and examples in parentheses was confusing to me, because responding by rendering the org switcher doesn't seem to fall into the category of an appropriate error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

73ce834

How does that feel?

Comment on lines 471 to 474
Common examples:
- `["/orgs/:slug", "/orgs/:slug/(.*)"]`
- `["/orgs/:id", "/orgs/:id/(.*)"]`
- `["/app/:any/orgs/:slug", "/app/:any/orgs/:slug/(.*)"]`
Copy link
Member

Choose a reason for hiding this comment

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

❓ Would it be helpful to provide some examples that would match these?

Copy link
Member

Choose a reason for hiding this comment

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

Oh I just saw the section on Patterns, so maybe this isn't as necessary

Copy link

Hey, here’s your docs preview: https://clerk.com/docs/pr/1634

izaaklauer and others added 3 commits October 22, 2024 10:33
It causes our linter to fail: https://github.com/clerk/clerk-docs/actions/runs/11462466478/job/31893925923?pr=1634

it'd be nice if the linter allowed for glossary links, but i'm not going to move that boulder today.
@alexisintech alexisintech changed the title Izaak/orgs 132 document org sync middleware options Izaak/orgs 132 Add organizationSyncOptions prop to clerkMiddleware() options Oct 23, 2024
@alexisintech alexisintech changed the title Izaak/orgs 132 Add organizationSyncOptions prop to clerkMiddleware() options Add organizationSyncOptions prop to clerkMiddleware() options Oct 23, 2024
docs/references/nextjs/clerk-middleware.mdx Outdated Show resolved Hide resolved
docs/references/nextjs/clerk-middleware.mdx Outdated Show resolved Hide resolved
docs/references/nextjs/clerk-middleware.mdx Outdated Show resolved Hide resolved
docs/references/nextjs/clerk-middleware.mdx Outdated Show resolved Hide resolved
docs/references/nextjs/clerk-middleware.mdx Outdated Show resolved Hide resolved
@izaaklauer izaaklauer force-pushed the izaak/orgs-132-document-org-sync-middleware-options branch from b273bfa to 7c750bc Compare October 25, 2024 15:34
@izaaklauer
Copy link
Contributor Author

Thank you @victoriaxyz for those improvements!

@victoriaxyz victoriaxyz self-requested a review October 28, 2024 21:37
docs/references/nextjs/clerk-middleware.mdx Outdated Show resolved Hide resolved
docs/references/nextjs/clerk-middleware.mdx Outdated Show resolved Hide resolved
docs/references/nextjs/clerk-middleware.mdx Outdated Show resolved Hide resolved
docs/references/nextjs/clerk-middleware.mdx Outdated Show resolved Hide resolved
victoriaxyz and others added 5 commits October 30, 2024 15:38
This reverts commit 0220928.

Decided that we like the personal account highlight. Here's my justification for any future readers who are interested

In general, our section links are quite good - the section title we link to makes it clear that the article is talking about the term of interest.
In this case, we don't have a "personal account" definition to jump to with a section link. As a user, if I was promised the definition of Personal Account and the link went to https://clerk.com/docs/organizations/organization-workspaces#organization-workspaces-in-the-clerk-dashboard,  there's a good chance i'd read the long title and think "ugh, I don't want to read up on the complete theory of organization workspaces in the dashboard right now thank you", and navigate away. I think the text highlight would point me to the part i'm actually interested in!

It's a little bit brittle though - if we restructure the page in the future so that the first appearance of "Personal account" isn't the definition, this will seem broken. Tradeoffs! I think it's worth it in this case, but not a big deal either way.
This reverts commit e9ff7c3.

We like the test highlighting after all. My justification for anyone interested:

In general, our section links are quite good - the section title we link to makes it clear that the article is talking about the term of interest.
In this case, we don't have a "personal account" definition to jump to with a section link. As a user, if I was promised the definition of Personal Account and the link went to https://clerk.com/docs/organizations/organization-workspaces#organization-workspaces-in-the-clerk-dashboard,  there's a good chance i'd read the long title and think "ugh, I don't want to read up on the complete theory of organization workspaces in the dashboard right now thank you", and navigate away. I think the text highlight would point me to the part i'm actually interested in!

It's a little bit brittle though - if we restructure the page in the future so that the first appearance of "Personal account" isn't the definition, this will seem broken. Tradeoffs! I think it's worth it in this case, but not a big deal either way.
After actually digesting https://clerk.com/docs/organizations/organization-workspaces#organization-workspaces-in-the-clerk-dashboard, i think that's probably not the best thing to link to! The use-case i'm talking to isn't about the dashboard at all - it's building custom apps. The dashboard happens to consume this feature also, so it has "personal accounts", but those docs are specifically about what personal accounts mean to the dashboard, not to any application.
- `organizationSyncOptions?`
- <code>[OrganizationSyncOptions](#organization-sync-options) | undefined</code>

Used to activate a specific [organization](docs/organizations/overview) or [personal account](https://clerk.com/glossary#personal-account) based on URL path parameters. If there's a mismatch between the active organization in the session (e.g., as reported by [`auth()`](/docs/references/nextjs/auth)) and the organization indicated by the URL, the middleware will attempt to activate the organization specified in the URL.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Used to activate a specific [organization](docs/organizations/overview) or [personal account](https://clerk.com/glossary#personal-account) based on URL path parameters. If there's a mismatch between the active organization in the session (e.g., as reported by [`auth()`](/docs/references/nextjs/auth)) and the organization indicated by the URL, the middleware will attempt to activate the organization specified in the URL.
Used to activate a specific [organization](docs/organizations/overview) or [personal account](/docs/organizations/organization-workspaces#organization-workspaces-in-the-clerk-dashboard:~:text=Personal%20account) based on URL path parameters. If there's a mismatch between the active organization in the session (e.g., as reported by [`auth()`](/docs/references/nextjs/auth)) and the organization indicated by the URL, the middleware will attempt to activate the organization specified in the URL.

- `string`

An alternative sign up URL.
The Clerk secret key for your instance. This can be found in your Clerk Dashboard on the **[API Keys](https://dashboard.clerk.com/last-active?path=api-keys)** page. The `CLERK_ENCRYPTION_KEY` environment variable must be set when providing `secretKey` as an option. For more information, refer to [Dynamic keys](#dynamic-keys) section.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The Clerk secret key for your instance. This can be found in your Clerk Dashboard on the **[API Keys](https://dashboard.clerk.com/last-active?path=api-keys)** page. The `CLERK_ENCRYPTION_KEY` environment variable must be set when providing `secretKey` as an option. For more information, refer to [Dynamic keys](#dynamic-keys) section.
The Clerk secret key for your instance. This can be found in your Clerk Dashboard on the **[API Keys](https://dashboard.clerk.com/last-active?path=api-keys)** page. The `CLERK_ENCRYPTION_KEY` environment variable must be set when providing `secretKey` as an option. For more information, refer to the [Dynamic keys](#dynamic-keys) section.

Patterns must have a path parameter named either `:id` (to match a Clerk organization ID) or `:slug` (to match a Clerk organization slug).

> [!WARNING]
> If the organization can't be activated—either because it doesn't exist or the user lacks access—the previously active organization will remain unchanged. Components must detect this case and provide an appropriate error and/or resolution pathway, such as calling `notFound()` or displaying an [organization switcher](/docs/components/organization/organization-switcher).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> If the organization can't be activated—either because it doesn't exist or the user lacks access—the previously active organization will remain unchanged. Components must detect this case and provide an appropriate error and/or resolution pathway, such as calling `notFound()` or displaying an [organization switcher](/docs/components/organization/organization-switcher).
> If the organization can't be activated—either because it doesn't exist or the user lacks access—the previously active organization will remain unchanged. Components must detect this case and provide an appropriate error and/or resolution pathway, such as calling `notFound()` or displaying an [`<OrganizationSwitcher />`](/docs/components/organization/organization-switcher).

- <code>[Pattern](#pattern)\[]</code>

Specifies URL patterns that are organization-specific, containing an organization ID or slug as a path parameter. If a request
matches this path, the organization identifier will be extracted and activated before rendering.
Copy link
Member

Choose a reason for hiding this comment

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

when you say "the organization identifier will be activated", do you mean the organization identifier will be used to set that org as active?

- `personalAccountPatterns`
- <code>[Pattern](#pattern)\[]</code>

URL patterns for resources that exist within the context of a [Clerk Personal Account](https://clerk.com/glossary#personal-account) (user-specific, outside any
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
URL patterns for resources that exist within the context of a [Clerk Personal Account](https://clerk.com/glossary#personal-account) (user-specific, outside any
URL patterns for resources that exist within the context of a [Clerk Personal Account](/docs/organizations/organization-workspaces#organization-workspaces-in-the-clerk-dashboard:~:text=Personal%20account) (user-specific, outside any

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.

4 participants