@kirill.konshin/lint 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "tanstack-intent"
6
6
  ],
7
- "version": "0.8.2",
7
+ "version": "0.8.3",
8
8
  "type": "module",
9
9
  "skipGenerate": true,
10
10
  "bin": {
package/rules/auth.md CHANGED
@@ -6,24 +6,16 @@ paths:
6
6
  - '**/*.ts'
7
7
  ---
8
8
 
9
- - ALWAYS use [`@kirill.konshin/auth`](https://github.com/kirill-konshin/utils/tree/main/packages/auth) ([npm](https://www.npmjs.com/package/@kirill.konshin/auth)) for authentication in Next.js apps, NEVER hand-roll `iron-session` wrappers
10
- - Follow the canonical patterns from the [package README](https://github.com/kirill-konshin/utils/blob/main/packages/auth/README.md) (session module, layout guard, login page, actions, route handlers, proxy) and its migration table when refactoring existing hand-rolled auth
11
- - ONE auth instance per app in `src/auth.ts`: `createPasswordAuth` (password-protected admin) or `createAuth` (token/OAuth)
12
- - `isValid` defaults to checking the lib-owned `AUTHENTICATED` marker field (set by `login()`, default session shape `PasswordSession`, nothing to configure) — token/OAuth apps pass their own session type + `isValid` (e.g. access token present & not expired)
13
- - Pass Next's `Route` as the routes generic (`createPasswordAuth<Route>` / `createAuth<Session, Route>`) so `urls` and the return-URL helpers are type-checked (`typedRoutes` is set by `defineNextConfig`, see [nextjs.md](nextjs.md))
14
- - Auth module MUST start with `import 'server-only'` and MUST NOT be module-level `'use server'` (that would expose session getters as callable server actions) — export `loginAction`/`logoutAction` from the SAME module as thin async wrappers with function-level `'use server'`, NO separate `actions.ts`; plain re-exports (`export const loginAction = auth.loginFormAction`) are NOT registered as actions; ENFORCED BY AGENT: no ESLint rule checks this, add on creation, flag on review (see [nextjs.md](nextjs.md))
15
- - Client Components MUST NOT import the auth module (`server-only` + function-level actions are not client-importable) — Server Components pass `loginAction`/`logoutAction` down as props
16
- - Cookie name MUST be unique per app (`<app>_session`), NEVER generic `session`
17
- - Cookie secret `SESSION_SECRET` (≥32 chars) and login password `ADMIN_PASSWORD` are SEPARATE env vars, never reuse one for the other
18
- - NEVER compare passwords with `===`, use `verifyPassword` / `timingSafeEqualStrings` (timing-safe)
19
- - Guard pages/layouts with `redirectNonAuthenticated()` (redirects to login), Server Actions and Route Handlers with `throwNonAuthenticated()` or `authenticatedRouteHandler()` (401), the whole `/api` surface with `proxyGuard()` in `proxy.ts`, login page with `redirectIfAuthenticated()`
20
- - Declare API visibility as `urls.public` / `urls.protected` globs and keep them exhaustive — `proxyGuard()` throws on overlap and warns (treating as public) on unknown paths; `allow` is only for request-level tweaks
21
- - Session lifetime via `ttl` (seconds) ONLY, NEVER set `cookieOptions.maxAge` (iron-session derives it)
22
- - Logout via `auth.logout()` (destroy + redirect) — export `logoutAction` as a function-level `'use server'` wrapper, like `loginAction`; a `FormData` argument from `<form action>` is ignored
23
- - Preserve the return URL through the `state` search param / hidden form field on login redirects; ALWAYS extract it with `auth.getState()` (accepts `await searchParams`, `URLSearchParams`, `FormData`, `NextRequest`, raw string; allows internal paths only, never the login page, falls back to `urls.afterLogin`), NEVER hand-parse `state`
24
- - NEVER store the return URL in the session — concurrent tabs share the cookie and would clash; thread it ONLY via search params, form fields and the `x-pathname` header
25
- - `proxy.ts` is two lines: `export const config = { matcher: [...] };` (a LITERAL — Next.js parses it statically) + `export const proxy = auth.proxyGuard({ matcher: config.matcher });` — the guard verifies the matcher covers all `urls.public`/`urls.protected` globs (it may be broader) and THROWS on uncovered ones
26
- - Login page is ONE Server Component file with `<form action={loginAction}>` (wrapping `auth.loginAction`) — errors return via the `?error=` search param; a Client Component (`useActionState` + `loginFormAction`) ONLY when pending/inline-error UI is actually needed
27
- - Reuse `auth.urls.*` (resolved, defaults applied) instead of repeating route literals, e.g. `redirect(auth.urls.afterLogin)`
28
- - List page routes in `urls.public` — `proxyGuard()` stamps `x-pathname` so `redirectNonAuthenticated()` returns users to the deep page after login (pages are enforced by layouts, not by the proxy)
29
- - Login page MUST live OUTSIDE the guarded layout (the guard would redirect to itself); `urls.afterLogin` pointing at the login page throws at creation
9
+ Patterns, strategies, Neon Auth setup, password login and migration: the `auth` skill of `@kirill.konshin/auth`, it installs with the package.
10
+
11
+ - ALWAYS use [`@kirill.konshin/auth`](https://github.com/kirill-konshin/utils/tree/main/packages/auth) ([npm](https://www.npmjs.com/package/@kirill.konshin/auth)) for authentication in Next.js apps, NEVER hand-roll `iron-session` or Neon Auth session wrappers
12
+ - ONE auth instance per app in `src/auth.ts`, with ONE session strategy: `ironStrategy` (the app writes a sealed cookie; `createPasswordAuth` for password admin) or `neonStrategy` (Neon Auth owns the session); NEVER wrap one session into another
13
+ - Auth module MUST start with `import 'server-only'` and MUST NOT be module-level `'use server'`; `loginAction`/`logoutAction` are function-level `'use server'` wrappers in the SAME module, plain re-exports are NOT registered as actions; ENFORCED BY AGENT: no ESLint rule checks this, add on creation, flag on review (see [nextjs.md](nextjs.md))
14
+ - Client Components MUST NOT import the auth module; Server Components pass `loginAction`/`logoutAction` down as props
15
+ - Code outside Next (agent runtimes, workers) MUST NOT import the auth module: it asks a Next Route Handler for the session, forwarding the request's `cookie` header
16
+ - Iron: cookie name unique per app (`<app>_session`); `SESSION_SECRET` (≥32 chars) and `ADMIN_PASSWORD` are SEPARATE env vars; lifetime via `ttl` ONLY, NEVER `cookieOptions.maxAge`
17
+ - NEVER compare passwords with `===`, use `verifyPassword` / `timingSafeEqualStrings`
18
+ - Guard pages/layouts with `redirectNonAuthenticated()` (inside `<Suspense>`), Server Actions and Route Handlers with `throwNonAuthenticated()` or `authenticatedRouteHandler()`, the `/api` surface with `proxyGuard()` in `proxy.ts`, the login page with `redirectIfAuthenticated()`
19
+ - `proxy.ts`: a LITERAL `config.matcher` + `auth.proxyGuard({ matcher: config.matcher })`; `urls.public` / `urls.protected` globs stay exhaustive
20
+ - ALWAYS extract the return URL with `auth.getState()`, NEVER hand-parse `state`, NEVER store it in the session
21
+ - Login page lives OUTSIDE the guarded layout; logout via `auth.logout()`
package/rules/db.md CHANGED
@@ -28,4 +28,4 @@ Migration and import procedures, Neon: the `lint-db` skill.
28
28
  # Neon
29
29
 
30
30
  - Only if the user asks for Neon, or the project already uses it: follow the `lint-db` skill
31
- - Fold Neon Auth into Iron Session (the `lint-db` skill); this overrides the session wrapper, callback route and middleware of the `neon-auth` skill
31
+ - Neon Auth: `neonStrategy` of `@kirill.konshin/auth` (its `auth` skill); this overrides the session wrapper, callback route and middleware of the `neon-auth` skill
package/rules/nextjs.md CHANGED
@@ -16,7 +16,7 @@ Use the `lint-nextjs` skill when working with a Next.js project.
16
16
  - Prefer Route Handlers for redirects
17
17
  - Never use Pages Router
18
18
  - Always use App Router
19
- - Use `iron-session` for authentication via `@kirill.konshin/auth`, see [auth.md](auth.md)
19
+ - Use `@kirill.konshin/auth` for authentication (iron-session or Neon Auth strategy), see [auth.md](auth.md)
20
20
  - Server-only modules MUST start with `import 'server-only'`: see [typescript.md](typescript.md)
21
21
  - `package.json` MUST ALWAYS have version of Next.js, NEVER `*`, otherwise Vercel will fall into legacy mode instead of serverless
22
22
  - ALWAYS create `next.config.ts` with `defineNextConfig` from `@kirill.konshin/next/config` (the `/config` subpath, NEVER the barrel — Next transpiles `next.config.ts` to CJS and `require`s it outside any bundler); what it sets: the `next` skill of `@kirill.konshin/next`
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: lint-db
3
- description: Database procedures for the db rule - LocalStorage / IndexedDB to server migrations, transactional importers, one-off data transfers, steps after a schema change, Neon Auth folded into Iron Session. Use when migrating or importing data, changing a schema, or adding Neon Auth.
3
+ description: Database procedures for the db rule - LocalStorage / IndexedDB to server migrations, transactional importers, one-off data transfers, steps after a schema change. Use when migrating or importing data, or changing a schema.
4
4
  ---
5
5
 
6
6
  The binding rules are in [rules/db.md](../../rules/db.md). This skill holds the procedures.
@@ -16,8 +16,4 @@ The binding rules are in [rules/db.md](../../rules/db.md). This skill holds the
16
16
 
17
17
  Only when the user asks for Neon, or the project already uses it. Connection strings, branches and migrations: the `neon-postgres` skill and the `neon-postgres-branches` skill. Drivers, URLs and migration runs: `@kirill.konshin/db` and its `db` skill, it installs with the package.
18
18
 
19
- Neon Auth: set it up per the `neon-auth` skill, then fold it into Iron Session ([rules/auth.md](../../rules/auth.md)):
20
-
21
- 1. Link the Neon identity to the app user on the server.
22
- 2. Store the app context in the sealed Iron Session.
23
- 3. Clear the transient Neon session.
19
+ Neon Auth: the `auth` skill of `@kirill.konshin/auth` (`neonStrategy`), it installs with the package.
@@ -25,30 +25,7 @@ export default function Layout({ children, analytics }: LayoutProps<'/dashboard'
25
25
 
26
26
  ## Check auth in layouts pattern
27
27
 
28
- Put the auth guard in the layout of a route group, `app/(auth)/layout.tsx`: the group adds no path segment and protects every route below it.
29
-
30
- Layouts do not protect Route Handlers: check auth in each handler too.
31
-
32
- Use `@kirill.konshin/auth` (see [rules/auth.md](../../rules/auth.md)); the guard runs inside `<Suspense>`:
33
-
34
- ```tsx
35
- import { type ReactNode, Suspense } from 'react';
36
-
37
- import { auth } from '@/auth';
38
-
39
- export default function Layout({ children }: LayoutProps<'/dashboard'>) {
40
- return (
41
- <Suspense>
42
- <Protected>{children}</Protected>
43
- </Suspense>
44
- );
45
- }
46
-
47
- async function Protected({ children }: { children: ReactNode }) {
48
- await auth.redirectNonAuthenticated(); // redirects to urls.login
49
- return <>{children}</>;
50
- }
51
- ```
28
+ Put the auth guard in the layout of a route group, `app/(auth)/layout.tsx`: the group adds no path segment and protects every route below it. Layouts do not protect Route Handlers: check auth in each handler too. The guard and its `<Suspense>` boundary: the `auth` skill of `@kirill.konshin/auth`.
52
29
 
53
30
  # Pages
54
31