From e319c32e1aa86d4c5e544946b847a80cc1b6ab53 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:00:51 -0400 Subject: [PATCH 01/27] Alphabetizing middleware options --- docs/references/nextjs/clerk-middleware.mdx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index d3d09155f6..53d93d72df 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -343,31 +343,31 @@ The `clerkMiddleware()` function accepts an optional object. The following optio --- - - `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. It's also possible to dynamically set options based on the incoming request: From 36cbef2e20b3066a4078b3fd70105341762dca27 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:11:41 -0400 Subject: [PATCH 02/27] Documenting organizationSyncOptions --- docs/references/nextjs/clerk-middleware.mdx | 90 +++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 53d93d72df..af653b9787 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -336,6 +336,13 @@ The `clerkMiddleware()` function accepts an optional object. The following optio --- + - `organizationSyncOptions?` + - [OrganizationSyncOptions](#organization-sync-options) | undefined + + Used to activate a particular [organization](docs/organizations/overview) or the [personal account](/glossary#personal-account) based on path parameters in the URL. + + --- + - `proxyUrl?` - `string` @@ -428,3 +435,86 @@ 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`. + +This defines the options for automatically activating an organization or the [personal account](/glossary#personal-account) +based on the URL. This is useful for applications that require organization slugs or IDs to appear in URL paths. + +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. + +`OrganizationSyncOptions` has the following properties: + + + - `organizationPatterns` + - [Pattern](#pattern)\[] + + 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. + + Patterns must have a path parameter named either `:id` (matches a clerk organization ID) or `:slug` (matches a clerk + organization slug). + + > [!WARNING] + > If the organization cannot be activated, either because it does not exist or the user lacks access, + > 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.). + + Common examples: + - `["/orgs/:slug", "/orgs/:slug/(.*)"]` + - `["/orgs/:id", "/orgs/:id/(.*)"]` + - `["/app/:any/orgs/:slug", "/app/:any/orgs/:slug/(.*)"]` + + --- + + - `personalAccountPatterns` + - [Pattern](#pattern)\[] + + URL patterns for resources that exist within the context of a clerk [personal account](/glossary#personal-account) (user-specific, outside any + organization). + + If the route also matches the organizationPattern, the organizationPattern takes precedence. + + Common examples: + - `["/me", "/me/(.*)"]` + - `["/user/:any", "/user/:any/(.*)"]` + + +### 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`). +- Wildcard token, `(.*)`, which will match the remainder of the path. + +####

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` | ❌ | From 76ceb1be3be05df7b693374d036eb3e65c4ce455 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:46:02 -0400 Subject: [PATCH 03/27] Update docs/references/nextjs/clerk-middleware.mdx Co-authored-by: Mary Zhong --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index af653b9787..5ae28f9e15 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -459,7 +459,7 @@ to activate the given organization will be made. If the route also matches the personalAccountPatterns, this takes precedence. - Patterns must have a path parameter named either `:id` (matches a clerk organization ID) or `:slug` (matches a clerk + Patterns must have a path parameter named either `:id` (matches a Clerk organization ID) or `:slug` (matches a Clerk organization slug). > [!WARNING] From 73ce834fcd8913bc2cd41ef67ec313a4ac7a2f16 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Mon, 21 Oct 2024 16:14:05 -0400 Subject: [PATCH 04/27] Responding to https://github.com/clerk/clerk-docs/pull/1634/files#r1805465600 Thanks @mzhong9723 ! --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 5ae28f9e15..783d26537b 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -465,7 +465,7 @@ to activate the given organization will be made. > [!WARNING] > If the organization cannot be activated, either because it does not exist or the user lacks access, > 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 + > appropriate error and/or resolution pathway (e.g., `notFound()` and an > [organization switcher](/docs/components/organization/organization-switcher), etc.). Common examples: From ff0d75ef3631d2f2665bd9508eb9af4a00e5a2db Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Mon, 21 Oct 2024 16:19:01 -0400 Subject: [PATCH 05/27] Code formatting Thanks @mzhong9723 ! https://github.com/clerk/clerk-docs/pull/1634/files#r1805459686 --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 783d26537b..a7d497322d 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -457,7 +457,7 @@ to activate the given organization will be made. 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. + If the route also matches the `personalAccountPatterns`, this takes precedence. Patterns must have a path parameter named either `:id` (matches a Clerk organization ID) or `:slug` (matches a Clerk organization slug). From 39f784dee65beb276d7001b7f31ffbd7bc7a50b8 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:33:07 -0400 Subject: [PATCH 06/27] Running `npm run format` --- docs/references/nextjs/clerk-middleware.mdx | 36 +++++++++++---------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index a7d497322d..e6794cfc06 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -469,6 +469,7 @@ to activate the given organization will be made. > [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/(.*)"]` @@ -484,6 +485,7 @@ to activate the given organization will be made. If the route also matches the organizationPattern, the organizationPattern takes precedence. Common examples: + - `["/me", "/me/(.*)"]` - `["/user/:any", "/user/:any/(.*)"]` @@ -491,30 +493,30 @@ to activate the given organization will be made. ### 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`). - Wildcard token, `(.*)`, which will match the remainder of the path. ####

Examples

- - `/orgs/:slug` - - | URL | Matches | `:slug` value | - |---------------------------|---------|---------------| - | `/orgs/acmecorp` | ✅ | `acmecorp` | - | `/orgs` | ❌ | n/a | - | `/orgs/acmecorp/settings` | ❌ | n/a | +- `/orgs/:slug` +| URL | Matches | `:slug` value | +| - | - | - | +| `/orgs/acmecorp` | ✅ | `acmecorp` | +| `/orgs` | ❌ | n/a | +| `/orgs/acmecorp/settings` | ❌ | n/a | - - `/app/:any/orgs/:id` +- `/app/:any/orgs/:id` - | URL | Matches | `:id` value | - |---------------------------------|---------|-------------| - | `/app/petstore/orgs/org_123` | ✅ | `org_123` | - | `/app/dogstore/v2/orgs/org_123` | ❌ | n/a | +| URL | Matches | `:id` value | +| - | - | - | +| `/app/petstore/orgs/org_123` | ✅ | `org_123` | +| `/app/dogstore/v2/orgs/org_123` | ❌ | n/a | - - `/personal-account/(.*)` +- `/personal-account/(.*)` - | URL | Matches | - |------------------------------|---------| - | `/personal-account/settings` | ✅ | - | `/personal-account` | ❌ | +| URL | Matches | +| - | - | +| `/personal-account/settings` | ✅ | +| `/personal-account` | ❌ | From a3e531ac1ec4ee7efbff66f35346ee1842dbc15b Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:08:15 -0400 Subject: [PATCH 07/27] Not relative linking to the glossary. 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. --- docs/references/nextjs/clerk-middleware.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index e6794cfc06..e5614409a9 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -339,7 +339,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `organizationSyncOptions?` - [OrganizationSyncOptions](#organization-sync-options) | undefined - Used to activate a particular [organization](docs/organizations/overview) or the [personal account](/glossary#personal-account) based on path parameters in the URL. + 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. --- @@ -441,7 +441,7 @@ export default clerkMiddleware( The `organizationSyncOptions` property on the [clerkMiddleware()](#clerk-middleware-options) options object has the type `OrganizationSyncOptions`. -This defines the options for automatically activating an organization or the [personal account](/glossary#personal-account) +This defines the options for automatically activating an organization or the [personal account](https://clerk.com/glossary#personal-account) based on the URL. This is useful for applications that require organization slugs or IDs to appear in URL paths. If a mismatch between the active organization on the session (e.g. as reported by @@ -479,7 +479,7 @@ to activate the given organization will be made. - `personalAccountPatterns` - [Pattern](#pattern)\[] - URL patterns for resources that exist within the context of a clerk [personal account](/glossary#personal-account) (user-specific, outside any + URL patterns for resources that exist within the context of a clerk [personal account](https://clerk.com/glossary#personal-account) (user-specific, outside any organization). If the route also matches the organizationPattern, the organizationPattern takes precedence. From 88b32cd3f5189912109f4e13ea8ba0a79d961497 Mon Sep 17 00:00:00 2001 From: Alexis Aguilar <98043211+alexisintech@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:54:30 -0400 Subject: [PATCH 08/27] code review --- docs/references/nextjs/clerk-middleware.mdx | 23 +++++++-------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index e5614409a9..9f989f12b4 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -339,7 +339,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `organizationSyncOptions?` - [OrganizationSyncOptions](#organization-sync-options) | undefined - 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. + 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. --- @@ -436,19 +436,10 @@ export default clerkMiddleware( > [!NOTE] > Dynamic keys are not accessible on the client-side. -### OrganizationSyncOptions +### `OrganizationSyncOptions` -The `organizationSyncOptions` property on the [clerkMiddleware()](#clerk-middleware-options) options -object has the type `OrganizationSyncOptions`. - -This defines the options for automatically activating an organization or the [personal account](https://clerk.com/glossary#personal-account) -based on the URL. This is useful for applications that require organization slugs or IDs to appear in URL paths. - -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. - -`OrganizationSyncOptions` has the following properties: +The `organizationSyncOptions` property on the [`clerkMiddleware()`](#clerk-middleware-options) options +object has the type `OrganizationSyncOptions`, which has the following properties: - `organizationPatterns` @@ -457,7 +448,7 @@ to activate the given organization will be made. 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. + 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). @@ -482,7 +473,7 @@ to activate the given organization will be made. URL patterns for resources that exist within the context of a clerk [personal account](https://clerk.com/glossary#personal-account) (user-specific, outside any organization). - If the route also matches the organizationPattern, the organizationPattern takes precedence. + If the route also matches the `organizationPattern` prop, the `organizationPattern` prop takes precedence. Common examples: @@ -497,7 +488,7 @@ A `Pattern` is a `string` that represents the structure of a URL path. In additi - Named path parameters prefixed with a colon (e. g., `:id`, `:slug`, `:any`). - Wildcard token, `(.*)`, which will match the remainder of the path. -####

Examples

+#### Examples - `/orgs/:slug` From 7c750bc4eed8b40461d242fbf5d1719c05149fde Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:31:20 -0400 Subject: [PATCH 09/27] Update docs/references/nextjs/clerk-middleware.mdx Co-authored-by: victoria --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index d673ff32ca..56583819ff 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -341,7 +341,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `organizationSyncOptions?` - [OrganizationSyncOptions](#organization-sync-options) | undefined - 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. + 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. --- From cf341d2e71800b3c62ccdcac6051ec5fc63f2ac8 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:38:04 -0400 Subject: [PATCH 10/27] Update docs/references/nextjs/clerk-middleware.mdx Co-authored-by: victoria --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 56583819ff..cc7469e857 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -355,7 +355,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `publishableKey` - `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. + 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. --- From 21a34ee7daa021d3904ef9c7619830d2e517dc33 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:39:08 -0400 Subject: [PATCH 11/27] Apply suggestions from code review Co-authored-by: victoria --- docs/references/nextjs/clerk-middleware.mdx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index cc7469e857..6905115943 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -369,14 +369,14 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `signInUrl?` - `string` - An alternative sign in URL. + An alternative sign-in URL. --- - `signUpUrl?` - `string` - An alternative sign up URL. + An alternative sign-up URL.
It's also possible to dynamically set options based on the incoming request: @@ -452,11 +452,10 @@ object has the type `OrganizationSyncOptions`, which has the following propertie 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). + 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 cannot be activated, either because it does not exist or the user lacks access, + > If the organization cannot be activated, either because it doesn't exist or the user lacks access, > 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.). @@ -472,7 +471,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie - `personalAccountPatterns` - [Pattern](#pattern)\[] - 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](https://clerk.com/glossary#personal-account) (user-specific, outside any organization). If the route also matches the `organizationPattern` prop, the `organizationPattern` prop takes precedence. From 90ad16deafd71d832c22cce78e5d48619bb3179c Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:26:37 -0400 Subject: [PATCH 12/27] Repointing personal account links Thanks @victoriaxyz ! https://github.com/clerk/clerk-docs/pull/1634#discussion_r1819783785 --- docs/references/nextjs/clerk-middleware.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 4f3b90d467..f1c086bc93 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -341,7 +341,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `organizationSyncOptions?` - [OrganizationSyncOptions](#organization-sync-options) | undefined - 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. --- @@ -471,7 +471,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie - `personalAccountPatterns` - [Pattern](#pattern)\[] - 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 organization). If the route also matches the `organizationPattern` prop, the `organizationPattern` prop takes precedence. From 0b2bc4053529b2836647aa7fff33e3f7fa5f9783 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:29:52 -0400 Subject: [PATCH 13/27] Update docs/references/nextjs/clerk-middleware.mdx Co-authored-by: victoria --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index f1c086bc93..16d5a12541 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -362,7 +362,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `secretKey?` - `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). + 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. --- From 57e7acdbc2dae5f8fb29b8ec682f68f248720be3 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:34:37 -0400 Subject: [PATCH 14/27] Update docs/references/nextjs/clerk-middleware.mdx Co-authored-by: victoria --- docs/references/nextjs/clerk-middleware.mdx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 16d5a12541..c0b73d9cb4 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -455,10 +455,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie 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 cannot be activated, either because it doesn't exist or the user lacks access, - > 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.). + > 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). Common examples: From 176c50d396d2ae0e53151d7e8641ae74d6e02fb8 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:52:57 -0400 Subject: [PATCH 15/27] Update docs/references/nextjs/clerk-middleware.mdx Co-authored-by: victoria --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index c0b73d9cb4..3f12309e54 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -447,7 +447,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie - `organizationPatterns` - [Pattern](#pattern)\[] - URL patterns that are organization-specific and contain an organization ID or slug as a path parameter. If a request + 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. If the route also matches the `personalAccountPatterns` prop, this prop takes precedence. From 206ed7cf7282478e6e761f73a3e493999963a526 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:01:12 -0400 Subject: [PATCH 16/27] Update docs/references/nextjs/clerk-middleware.mdx Co-authored-by: victoria --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 3f12309e54..001bb043f6 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -483,7 +483,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie 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`). +- Named path parameters prefixed with a colon (e.g., `:id`, `:slug`, `:any`). - Wildcard token, `(.*)`, which will match the remainder of the path. #### Examples From e9ff7c3bbe9d761abba135402593b97c0148223c Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:01:20 -0400 Subject: [PATCH 17/27] Update docs/references/nextjs/clerk-middleware.mdx Co-authored-by: victoria --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 001bb043f6..470c48c3c3 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -341,7 +341,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `organizationSyncOptions?` - [OrganizationSyncOptions](#organization-sync-options) | undefined - 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. + Used to activate a specific [organization](docs/organizations/overview) or [personal account](/docs/organizations/organization-workspaces#organization-workspaces-in-the-clerk-dashboard) 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. --- From 0220928bc9352ab34fbf9584317364e135ea727f Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:01:26 -0400 Subject: [PATCH 18/27] Update docs/references/nextjs/clerk-middleware.mdx Co-authored-by: victoria --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 470c48c3c3..ba3087ec7f 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -468,7 +468,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie - `personalAccountPatterns` - [Pattern](#pattern)\[] - 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 + URL patterns for resources that exist within the context of a [Clerk Personal Account](/docs/organizations/organization-workspaces#organization-workspaces-in-the-clerk-dashboard) (user-specific, outside any organization). If the route also matches the `organizationPattern` prop, the `organizationPattern` prop takes precedence. From 77fbfc17cf00a7e8bc5b76222fda85a41482e380 Mon Sep 17 00:00:00 2001 From: victoria Date: Wed, 30 Oct 2024 15:38:11 +0100 Subject: [PATCH 19/27] Update docs/references/nextjs/clerk-middleware.mdx --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index ba3087ec7f..c37fd359f5 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -484,7 +484,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie 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`). -- Wildcard token, `(.*)`, which will match the remainder of the path. +- Wildcard token, `(.*)`, which matches the remainder of the path. #### Examples From 828f7fa73686515dc35c0d2067607e8dcd77fcd0 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:34:41 -0400 Subject: [PATCH 20/27] Revert "Update docs/references/nextjs/clerk-middleware.mdx" This reverts commit 0220928bc9352ab34fbf9584317364e135ea727f. 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. --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index c37fd359f5..f0a19f3b1f 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -468,7 +468,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie - `personalAccountPatterns` - [Pattern](#pattern)\[] - URL patterns for resources that exist within the context of a [Clerk Personal Account](/docs/organizations/organization-workspaces#organization-workspaces-in-the-clerk-dashboard) (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 organization). If the route also matches the `organizationPattern` prop, the `organizationPattern` prop takes precedence. From 152dcb02f61c2506f58ab905bc6c5f6ab5cdaaf3 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:35:50 -0400 Subject: [PATCH 21/27] Revert "Update docs/references/nextjs/clerk-middleware.mdx" This reverts commit e9ff7c3bbe9d761abba135402593b97c0148223c. 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. --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index f0a19f3b1f..c5eec9ccfa 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -341,7 +341,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `organizationSyncOptions?` - [OrganizationSyncOptions](#organization-sync-options) | undefined - Used to activate a specific [organization](docs/organizations/overview) or [personal account](/docs/organizations/organization-workspaces#organization-workspaces-in-the-clerk-dashboard) 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. --- From fa1c4a5ec5c100ec321fe8bd3fbe3ba0d66b12fc Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:11:06 -0400 Subject: [PATCH 22/27] Reverting all the way back to the glossary. 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. --- docs/references/nextjs/clerk-middleware.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index c5eec9ccfa..f25e4dc575 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -341,7 +341,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `organizationSyncOptions?` - [OrganizationSyncOptions](#organization-sync-options) | undefined - 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. + 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. --- @@ -468,7 +468,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie - `personalAccountPatterns` - [Pattern](#pattern)\[] - 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 + URL patterns for resources that exist within the context of a [Clerk Personal Account](https://clerk.com/glossary#personal-account) (user-specific, outside any organization). If the route also matches the `organizationPattern` prop, the `organizationPattern` prop takes precedence. From c7662b2c1c894c8089fca02b38d8045f77050344 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:24:46 -0500 Subject: [PATCH 23/27] Update docs/references/nextjs/clerk-middleware.mdx Co-authored-by: Alexis Aguilar <98043211+alexisintech@users.noreply.github.com> --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index f25e4dc575..5a8578cba1 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -341,7 +341,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `organizationSyncOptions?` - [OrganizationSyncOptions](#organization-sync-options) | undefined - 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. --- From ecdb74391e7e6ddc808a08471be1ecb667299bd4 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:25:31 -0500 Subject: [PATCH 24/27] Apply suggestions from code review Co-authored-by: Alexis Aguilar <98043211+alexisintech@users.noreply.github.com> --- docs/references/nextjs/clerk-middleware.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 5a8578cba1..c6dd8d43af 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -362,7 +362,7 @@ The `clerkMiddleware()` function accepts an optional object. The following optio - `secretKey?` - `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. 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. --- @@ -455,7 +455,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie 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). + > 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 [``](/docs/components/organization/organization-switcher). Common examples: @@ -468,7 +468,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie - `personalAccountPatterns` - [Pattern](#pattern)\[] - 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 organization). If the route also matches the `organizationPattern` prop, the `organizationPattern` prop takes precedence. From 9eac79840c29d259ba416bd4d28744a54ffcce47 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:35:44 -0500 Subject: [PATCH 25/27] Removing rouge formatting change --- docs/references/nextjs/clerk-middleware.mdx | 117 ++++++++++---------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index c1eea5c594..a183926e6b 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -64,17 +64,17 @@ There are two methods that you can use: const isProtectedRoute = createRouteMatcher(['/dashboard(.*)', '/forum(.*)']) export default clerkMiddleware(async (auth, req) => { - if (isProtectedRoute(req)) await auth.protect() -}) + if (isProtectedRoute(req)) await auth.protect() + }) export const config = { - matcher: [ - // Skip Next.js internals and all static files, unless found in search params - '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', - // Always run for API routes - '/(api|trpc)(.*)', - ], -} + matcher: [ + // Skip Next.js internals and all static files, unless found in search params + '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', + // Always run for API routes + '/(api|trpc)(.*)', + ], + } ``` ```tsx {{ filename: 'app/middleware.ts' }} @@ -83,23 +83,23 @@ There are two methods that you can use: const isProtectedRoute = createRouteMatcher(['/dashboard(.*)', '/forum(.*)']) export default clerkMiddleware(async (auth, req) => { - const { userId, redirectToSignIn } = await auth() + const { userId, redirectToSignIn } = await auth() - if (!userId && isProtectedRoute(req)) { - // Add custom logic to run before redirecting + if (!userId && isProtectedRoute(req)) { + // Add custom logic to run before redirecting - return redirectToSignIn() -} -}) + return redirectToSignIn() + } + }) export const config = { - matcher: [ - // Skip Next.js internals and all static files, unless found in search params - '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', - // Always run for API routes - '/(api|trpc)(.*)', - ], -} + matcher: [ + // Skip Next.js internals and all static files, unless found in search params + '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', + // Always run for API routes + '/(api|trpc)(.*)', + ], + } ``` @@ -119,25 +119,25 @@ There are two methods that you can use: const isProtectedRoute = createRouteMatcher(['/admin(.*)']) export default clerkMiddleware(async (auth, req) => { - // Restrict admin routes to users with specific permissions - if (isProtectedRoute(req)) { - await auth.protect((has) => { - return ( - has({ permission: 'org:sys_memberships:manage' }) || - has({ permission: 'org:sys_domains_manage' }) - ) -}) -} -}) + // Restrict admin routes to users with specific permissions + if (isProtectedRoute(req)) { + await auth.protect((has) => { + return ( + has({ permission: 'org:sys_memberships:manage' }) || + has({ permission: 'org:sys_domains_manage' }) + ) + }) + } + }) export const config = { - matcher: [ - // Skip Next.js internals and all static files, unless found in search params - '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', - // Always run for API routes - '/(api|trpc)(.*)', - ], -} + matcher: [ + // Skip Next.js internals and all static files, unless found in search params + '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', + // Always run for API routes + '/(api|trpc)(.*)', + ], + } ``` ```tsx {{ filename: 'middleware.ts' }} @@ -146,26 +146,26 @@ There are two methods that you can use: const isProtectedRoute = createRouteMatcher(['/admin(.*)']) export default clerkMiddleware(async (auth, req) => { - const { has, redirectToSignIn } = await auth() - // Restrict admin routes to users with specific permissions - if ( - (isProtectedRoute(req) && !has({ permission: 'org:sys_memberships:manage' })) || - !has({ permission: 'org:sys_domains_manage' }) - ) { - // Add logic to run if the user does not have the required permissions - - return redirectToSignIn() -} -}) + const { has, redirectToSignIn } = await auth() + // Restrict admin routes to users with specific permissions + if ( + (isProtectedRoute(req) && !has({ permission: 'org:sys_memberships:manage' })) || + !has({ permission: 'org:sys_domains_manage' }) + ) { + // Add logic to run if the user does not have the required permissions + + return redirectToSignIn() + } + }) export const config = { - matcher: [ - // Skip Next.js internals and all static files, unless found in search params - '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', - // Always run for API routes - '/(api|trpc)(.*)', - ], -} + matcher: [ + // Skip Next.js internals and all static files, unless found in search params + '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', + // Always run for API routes + '/(api|trpc)(.*)', + ], + } ``` @@ -508,4 +508,5 @@ A `Pattern` is a `string` that represents the structure of a URL path. In additi | URL | Matches | | - | - | | `/personal-account/settings` | ✅ | -| `/personal-account` | ❌ | \ No newline at end of file +| `/personal-account` | ❌ | + From e26600da08e4000e86654a273c62e36e14dd95c1 Mon Sep 17 00:00:00 2001 From: Izaak Lauer <8404559+izaaklauer@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:37:51 -0500 Subject: [PATCH 26/27] Addressing https://github.com/clerk/clerk-docs/pull/1634#discussion_r1825905772 Thanks Alexis! --- docs/references/nextjs/clerk-middleware.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index a183926e6b..899b1cc45e 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -448,7 +448,7 @@ object has the type `OrganizationSyncOptions`, which has the following propertie - [Pattern](#pattern)\[] 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. + matches this path, the organization identifier will be used to set that org as active. If the route also matches the `personalAccountPatterns` prop, this prop takes precedence. From 75a9f87577654287efed38a977c939c40514f6a5 Mon Sep 17 00:00:00 2001 From: Alexis Aguilar <98043211+alexisintech@users.noreply.github.com> Date: Wed, 18 Dec 2024 18:21:25 -0500 Subject: [PATCH 27/27] format --- docs/references/nextjs/clerk-middleware.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/references/nextjs/clerk-middleware.mdx b/docs/references/nextjs/clerk-middleware.mdx index 899b1cc45e..1403953e07 100644 --- a/docs/references/nextjs/clerk-middleware.mdx +++ b/docs/references/nextjs/clerk-middleware.mdx @@ -509,4 +509,3 @@ A `Pattern` is a `string` that represents the structure of a URL path. In additi | - | - | | `/personal-account/settings` | ✅ | | `/personal-account` | ❌ | -