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

Merged
merged 33 commits into from
Dec 20, 2024
Merged
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e319c32
Alphabetizing middleware options
izaaklauer Oct 17, 2024
36cbef2
Documenting organizationSyncOptions
izaaklauer Oct 17, 2024
76ceb1b
Update docs/references/nextjs/clerk-middleware.mdx
izaaklauer Oct 21, 2024
73ce834
Responding to https://github.com/clerk/clerk-docs/pull/1634/files#r18…
izaaklauer Oct 21, 2024
ff0d75e
Code formatting
izaaklauer Oct 21, 2024
39f784d
Running `npm run format`
izaaklauer Oct 22, 2024
a3e531a
Not relative linking to the glossary.
izaaklauer Oct 22, 2024
88b32cd
code review
alexisintech Oct 23, 2024
607f55a
Merge branch 'main' into izaak/orgs-132-document-org-sync-middleware-…
victoriaxyz Oct 25, 2024
7c750bc
Update docs/references/nextjs/clerk-middleware.mdx
izaaklauer Oct 25, 2024
cf341d2
Update docs/references/nextjs/clerk-middleware.mdx
izaaklauer Oct 25, 2024
21a34ee
Apply suggestions from code review
izaaklauer Oct 25, 2024
c1e6f67
Merge branch 'main' into izaak/orgs-132-document-org-sync-middleware-…
victoriaxyz Oct 28, 2024
90ad16d
Repointing personal account links
izaaklauer Oct 29, 2024
0b2bc40
Update docs/references/nextjs/clerk-middleware.mdx
izaaklauer Oct 29, 2024
57e7acd
Update docs/references/nextjs/clerk-middleware.mdx
izaaklauer Oct 29, 2024
176c50d
Update docs/references/nextjs/clerk-middleware.mdx
izaaklauer Oct 29, 2024
109cca9
Merge branch 'main' into izaak/orgs-132-document-org-sync-middleware-…
victoriaxyz Oct 30, 2024
206ed7c
Update docs/references/nextjs/clerk-middleware.mdx
izaaklauer Oct 30, 2024
e9ff7c3
Update docs/references/nextjs/clerk-middleware.mdx
izaaklauer Oct 30, 2024
0220928
Update docs/references/nextjs/clerk-middleware.mdx
izaaklauer Oct 30, 2024
77fbfc1
Update docs/references/nextjs/clerk-middleware.mdx
victoriaxyz Oct 30, 2024
828f7fa
Revert "Update docs/references/nextjs/clerk-middleware.mdx"
izaaklauer Oct 30, 2024
152dcb0
Revert "Update docs/references/nextjs/clerk-middleware.mdx"
izaaklauer Oct 30, 2024
fa1c4a5
Reverting all the way back to the glossary.
izaaklauer Oct 30, 2024
1a6766b
Merge branch 'main' into izaak/orgs-132-document-org-sync-middleware-…
victoriaxyz Oct 31, 2024
bad272c
Merge branch 'main' into izaak/orgs-132-document-org-sync-middleware-…
victoriaxyz Nov 1, 2024
c7662b2
Update docs/references/nextjs/clerk-middleware.mdx
izaaklauer Dec 18, 2024
ecdb743
Apply suggestions from code review
izaaklauer Dec 18, 2024
365e075
Merge branch 'main' into izaak/orgs-132-document-org-sync-middleware-…
izaaklauer Dec 18, 2024
9eac798
Removing rouge formatting change
izaaklauer Dec 18, 2024
e26600d
Addressing https://github.com/clerk/clerk-docs/pull/1634#discussion_r…
izaaklauer Dec 18, 2024
75a9f87
format
alexisintech Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 91 additions & 8 deletions docs/references/nextjs/clerk-middleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -338,38 +338,45 @@ The `clerkMiddleware()` function accepts an optional object. The following optio

---

- `organizationSyncOptions?`
- <code>[OrganizationSyncOptions](#organization-sync-options) | undefined</code>

Used to activate a particular [organization](docs/organizations/overview) or the [personal account](https://clerk.com/glossary#personal-account) based on path parameters in the URL. If a mismatch between the active organization on the session (e.g. as reported by [`auth()`](/docs/references/nextjs/auth)) and the organization as indicated by the URL is detected, an attempt to activate the given organization will be made.
izaaklauer marked this conversation as resolved.
Show resolved Hide resolved

---

- `proxyUrl?`
- `string`

Specify the URL of the proxy, if using a proxy.

---

- `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.
izaaklauer marked this conversation as resolved.
Show resolved Hide resolved

---

- `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).
izaaklauer marked this conversation as resolved.
Show resolved Hide resolved

---

- `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.
izaaklauer marked this conversation as resolved.
Show resolved Hide resolved

---

- `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.

izaaklauer marked this conversation as resolved.
Show resolved Hide resolved
</Properties>

It's also possible to dynamically set options based on the incoming request:
Expand Down Expand Up @@ -430,3 +437,79 @@ export default clerkMiddleware(

> [!NOTE]
> Dynamic keys are not accessible on the client-side.

### `OrganizationSyncOptions`

The `organizationSyncOptions` property on the [`clerkMiddleware()`](#clerk-middleware-options) options
object has the type `OrganizationSyncOptions`, which has the following properties:

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

URL patterns that are organization-specific and contain an organization ID or slug as a path parameter. If a request
izaaklauer marked this conversation as resolved.
Show resolved Hide resolved
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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and I like your wording better!

e26600d


If the route also matches the `personalAccountPatterns` prop, this prop takes precedence.

Patterns must have a path parameter named either `:id` (matches a Clerk organization ID) or `:slug` (matches a Clerk
organization slug).
izaaklauer marked this conversation as resolved.
Show resolved Hide resolved

> [!WARNING]
> If the organization cannot be activated, either because it does not exist or the user lacks access,
izaaklauer marked this conversation as resolved.
Show resolved Hide resolved
> no change will be made to the previously active organization. Components must detect this case and respond with an
> appropriate error and/or resolution pathway (e.g., `notFound()` and an
> [organization switcher](/docs/components/organization/organization-switcher), etc.).

Common examples:

- `["/orgs/:slug", "/orgs/:slug/(.*)"]`
- `["/orgs/:id", "/orgs/:id/(.*)"]`
- `["/app/:any/orgs/:slug", "/app/:any/orgs/:slug/(.*)"]`

---

- `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
izaaklauer marked this conversation as resolved.
Show resolved Hide resolved
organization).

If the route also matches the `organizationPattern` prop, the `organizationPattern` prop takes precedence.

Common examples:

- `["/me", "/me/(.*)"]`
- `["/user/:any", "/user/:any/(.*)"]`
</Properties>

### Pattern

A `Pattern` is a `string` that represents the structure of a URL path. In addition to any valid URL, it may include:

- Named path parameters prefixed with a colon (e. g., `:id`, `:slug`, `:any`).
izaaklauer marked this conversation as resolved.
Show resolved Hide resolved
- Wildcard token, `(.*)`, which will match the remainder of the path.
victoriaxyz marked this conversation as resolved.
Show resolved Hide resolved

#### Examples

- `/orgs/:slug`

| URL | Matches | `:slug` value |
| - | - | - |
| `/orgs/acmecorp` | ✅ | `acmecorp` |
| `/orgs` | ❌ | n/a |
| `/orgs/acmecorp/settings` | ❌ | n/a |

- `/app/:any/orgs/:id`

| URL | Matches | `:id` value |
| - | - | - |
| `/app/petstore/orgs/org_123` | ✅ | `org_123` |
| `/app/dogstore/v2/orgs/org_123` | ❌ | n/a |

- `/personal-account/(.*)`

| URL | Matches |
| - | - |
| `/personal-account/settings` | ✅ |
| `/personal-account` | ❌ |
Loading