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:
+
+[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/(.*)"]`
+
[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:
[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 [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 [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 [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 [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 [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 [`[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` | ❌ |
-