You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c41f2ab
Browse filesBrowse the repository at this point in the historyBrowse files
|`protected`|`string[]` (required) | — |Project-relative folder globs whose resources must be guarded.|
99
-
|`public`|`string[]`|`[]`|Project-relative folder globs that are exempt. |
98
+
|`protected`|`string[]` (required) | — |Folder globs relative to the project root whose resources must be guarded. |
99
+
|`public`|`string[]`|`[]`|Folder globs relative to the project root that are exempt.|
100
100
|`resources`|`object`| all true | Resource groups to check. Supports `routeHandlers`, `serverFunctions`, and `serverComponentEntrypoints`, each as an optional boolean. |
101
101
|`mixedScopeLayouts`|`'auto' \| string[]`|`'auto'`| Layouts/templates that intentionally wrap both protected and public descendants. `'auto'` allows them silently; a list requires each such folder to be acknowledged explicitly. |
102
102
|`rootDir`|`string`|_(auto)_| Project root used to resolve project-relative folder globs. Defaults to the nearest ancestor `eslint.config.*`, then ESLint `cwd`. Set to `import.meta.dirname` in your config file when auto-discovery is unavailable. |
@@ -107,12 +107,12 @@ Globs use a minimal dialect — only `*` (single segment) and `**` (any depth).
107
107
108
108
`protected` and `public` are project-relative folder globs. Use `app/**` for a root `app` directory, `src/app/**` for a `src/app` directory, and `src/**`, `shared/**`, etc. for other project folders.
109
109
110
-
The project root is normally determined by the nearest `eslint.config.*` ancestor of the file being checked, and falls back to `cwd`. If you need better control, for example in a monorepo setup, you can specify `rootDir`; the globs will be relative to that directory.
110
+
The project root is normally determined by the nearest `eslint.config.*` ancestor of the file being checked, and falls back to `cwd`. You can configure it manually using `rootDir`.
111
111
112
112
We recommend starting with `protected: ['**']`. This protects the following resources by default:
113
113
114
-
- Server Functions are checked wherever they live in the project
115
-
- Regardless of configuration, App Router entrypoints like `page.jsx` or `route.js` are only checked if they live under a `app/`folder
114
+
- Server Functions are checked wherever they live in the project when their folder is protected
115
+
- Regardless of configuration, App Router entrypoints like `page.jsx` or `route.js` are only checked if they live under `app/` or `src/app/`relative to the project root
116
116
117
117
Use `public` for explicit exemptions:
118
118
@@ -165,6 +165,28 @@ Use `resources` to disable whole resource groups when a project only wants this
165
165
166
166
We recommend leaving all as true, but switching some off can be useful during incremental migrations. This configuration also scopes suggestions and bulk-fix tooling: disabled resource groups are not reported by the rule, so they will not receive editor quick-fixes or bulk-applied fixes.
167
167
168
+
## Monorepo setups
169
+
170
+
If you keep a separate `eslint.config.*` in each application, this rule will work with your monorepo setup out of the box.
171
+
172
+
If you have a single top level `eslint.config.*`, you need to define the rule once for each application, and you need to configure `rootDir` to point to each application root (for example `apps/web`). This makes sense when you consider that each `protected` and `public` pattern is application specific. For example:
173
+
174
+
```ts
175
+
{
176
+
files: ['apps/web/src/**/*.{ts,tsx}'],
177
+
rules: {
178
+
'@clerk/next/require-auth-protection': [
179
+
'error',
180
+
{
181
+
rootDir: 'apps/web',
182
+
protected: ['**'],
183
+
public: ['src/app/sign-in/**'],
184
+
}
185
+
]
186
+
}
187
+
}
188
+
```
189
+
168
190
## What counts as protected
169
191
170
192
The rule is satisfied when the relevant function guards itself at the top, either by calling `auth.protect()`:
# Scope fixes to a specific pattern, this will still
217
239
# use protected/public from your ESLint config, but
218
240
# can be useful to only fix a subset of your application
219
-
npx clerk-next-fix-auth-protection "src/app/**"
241
+
npx clerk-next-fix-auth-protection "src/**"
220
242
```
221
243
222
244
Resources the rule can't safely fix on its own (imported/wrapped exports, unacknowledged mixed-scope layouts) are listed as needing manual attention, and the command exits non-zero when any remain (or when `--dry-run` would make changes).
@@ -227,7 +249,7 @@ The same logic is available programmatically:
0 commit comments