Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Authjs Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-authjs-knowledge-patch-nevaberry-plugins)
---
name: authjs-knowledge-patch
description: Auth.js
version: "5.0.0"
license: MIT
metadata:
author: Nevaberry
---
# Auth.js Knowledge Patch
Load this skill when working on Auth.js authentication, provider configuration,
session handling, adapters, framework integration, or the Better Auth transition.
Use the matching reference for configuration examples and detailed behavior.
## Reference index
| Reference | Topics |
| --- | --- |
| [Adapters, Operations, and Security](references/adapters-operations-and-security.md) | Account fields, adapter contracts, dependency fixes, corporate proxies, logging, OAuth checks, host precedence, CommonJS |
| [Better Auth Transition](references/better-auth-transition.md) | Maintenance, project choice, migration guide |
| [Providers and Authentication](references/providers-and-authentication.md) | Credentials, email providers, magic links, OAuth configuration and linking, experimental Passkey setup and migration |
| [Sessions and Framework Integrations](references/sessions-and-frameworks.md) | JWT and database sessions, provider token refresh, Qwik, SvelteKit, Express, integration scaffold |
| [Auth.js v5 Migration and Next.js Integration](references/v5-migration.md) | Next.js 16 Proxy runtime and passkeys on custom Next.js pages |
## Maintenance and project choice
Better Auth now maintains Auth.js (NextAuth.js), providing security patches and
urgent fixes for existing installations. The transition announcement recommends
Better Auth for new projects, with database-free stateless sessions as the main
exception. The [transition reference](references/better-auth-transition.md)
includes the NextAuth.js migration guide.
## Compatibility and security changes
### OAuth checks and malformed tokens
OAuth state, nonce, and PKCE check cookies are bound to their creating provider.
A callback handled by another provider rejects those cookies. Restart OAuth
sign-ins in progress during an upgrade if their callbacks fail.
`getToken()` returns `null` for a malformed Bearer value in the `Authorization`
header. Handle this through the same path as a missing token.
### Host precedence and CommonJS
In trusted-host mode, an explicitly configured `NEXTAUTH_URL` takes precedence
over the host auto-detected from forwarded headers.
The CommonJS compatibility fix uses `uuid@^11.1.1`, restoring loading of
`next-auth` via `require()` on Node.js versions earlier than 20.19.
See [operations and security](references/adapters-operations-and-security.md)
for the release attribution of these changes.
### Package-specific fixes
- `@auth/kysely-adapter@1.11.2` requires `kysely@^0.28.15` to address
CVE-2026-33468. Update the application's `kysely` dependency and lockfile
when upgrading the adapter.
- Upgrade to `@auth/sveltekit@1.11.1` or later for the Nodemailer security fix.
- `next-auth@4.24.14` sets the built-in GitHub provider's default issuer to
`https://github.com/login/oauth`. Upgrade if GitHub sign-in on an older v4
release fails when `openid-client` validates the `iss` callback parameter.
## Next.js Proxy
Next.js 16 moves `middleware.ts` to `proxy.ts` and runs Proxy on Node.js.
Proxy can use the main Auth.js configuration with an adapter requiring Node.js.
```ts
// proxy.ts
export { auth as proxy } from "./auth"
```
See [Next.js integration](references/v5-migration.md).
## Credentials failures
Returning `null` from `authorize` redirects built-in pages to sign-in with
`?error=CredentialsSignin&code=credentials`. In server form actions, catch the
thrown `CredentialsSignin`. For a custom public `code`, throw an instance of a
subclass from `authorize`:
```ts
class InvalidLogin extends CredentialsSignin {
code = "invalid_credentials"
}
```
## Email and magic links
Add `ForwardEmail`, `Sendgrid`, `Postmark`, or `Mailgun` to `providers` and set
the matching environment key. Their sign-in IDs are `forwardemail`, `sendgrid`,
`postmark`, and `mailgun`.
```dotenv
AUTH_FORWARDEMAIL_KEY=your-api-key
AUTH_SENDGRID_KEY=your-api-key
AUTH_POSTMARK_KEY=your-api-key
AUTH_MAILGUN_KEY=your-api-key
```
- Loops receives the magic link as its only template data variable,
case-sensitive `url`. Pass its API key and Transactional ID in provider options.
- For custom HTTP email delivery, configure an `email` provider with a database
adapter and implement `sendVerificationRequest` to send `url` to `identifier`.
Start the flow with `signIn("http-email", { email })`.
- Email sign-in applies Unicode NFKC normalization before validating the address.
- An address can have several outstanding `VerificationToken` rows. Each token
is single-use and expires after one day by default; the email provider's
`maxAge` configures this in seconds. Periodically remove expired rows from
unfinished sign-ins.
See [providers and authentication](references/providers-and-authentication.md)
for the Loops configuration, HTTP delivery example, and token lifetime example.
## OAuth configuration and accounts
- For Apple, register the application's callback URL directly and leave
`redirectProxyUrl` unset.
- To link a second OAuth account with the same email, sign in to the existing
user first, then complete sign-in with the second provider. Manual unlinking
requires an adapter implementing `unlinkAccount`.
- Use a provider's `account()` callback to choose persisted token fields; add
matching adapter schema columns for extra fields it returns.
- Auth.js runs OAuth on the server as a confidential client. Native mobile and
desktop apps running OAuth directly need a public-client flow.
- Route provider OAuth requests through a corporate proxy with `[customFetch]`.
With Undici, pass a `ProxyAgent` as the fetch dispatcher.
The [provider reference](references/providers-and-authentication.md) covers
account linking and provider configuration. The
[adapter reference](references/adapters-operations-and-security.md) lists the
default persisted fields and includes the `account()` and proxy examples.
## Experimental Passkey
Use Node.js 20 or later, `@simplewebauthn/server@9.0.3`, and a compatible database
adapter. The provider guide lists minimum versions of `next-auth@5.0.0-beta.17`
or `@auth/sveltekit@1.0.2`, with `@auth/prisma-adapter@1.3.3`,
`@auth/unstorage-adapter@2.1.0`, or `@auth/drizzle-adapter@1.1.1`.
Apply the adapter's authenticator migration before enabling Passkey. The
[provider reference](references/providers-and-authentication.md) includes the
Prisma model and configuration with `experimental: { enableWebAuthn: true }`.
For custom Next.js pages, install `@simplewebauthn/browser@9.0.1` and import
`signIn` from `next-auth/webauthn` in a client component. Use the registration
handler for signed-in users adding a passkey and the sign-in handler for
signed-out users. See the [handlers](references/v5-migration.md).
## Session storage and provider token refresh
An adapter can store users and accounts without a database `Session` model
when JWT sessions are explicitly selected:
```ts
session: { strategy: "jwt" },
```
When reading database sessions, Auth.js checks `expires` and deletes expired
session rows. Session cookies exceeding the roughly 4 KB per-cookie limit are
split into chunks and reassembled on reads. Session endpoint GET requests
include headers preventing caching by default.
For provider token refresh with database sessions, use
`callbacks.session({ session, user })` to look up the account using `user.id`.
Compare its `expires_at` in Unix seconds with the current time. After a successful
refresh, update the account identified by `(provider, providerAccountId)` with
the new `access_token` and `expires_at`; preserve the stored `refresh_token`
if the response omits a replacement.
## Framework session access and actions
- Qwik: export `onRequest` and `useSession` from `QwikAuth$` in
`src/routes/plugin@auth.ts`. Components read `useSession().value`; page and
layout request handlers read `event.sharedMap`. Pass `useSignIn` and
`useSignOut` return values to Qwik City's `<Form>`. Sign-in fields use
`providerId` and `options.redirectTo`; sign-out uses top-level `redirectTo`.
- SvelteKit: re-export the `SvelteKitAuth` handle from `hooks.server.ts` for
`event.locals.auth()` in `+page.server.ts`, `+layout.server.ts`, and `+server.ts`.
Return `{ session: await locals.auth() }` from a server load for `data.session`.
`SignIn` and `SignOut` from `@auth/sveltekit/components` post to `/signin`
and `/signout` by default; the reference covers destination props and actions.
- Express: mount `ExpressAuth(authConfig)` under `/auth`. Call `getSession` from
`@auth/express` with the incoming request and the same config; store the session
on `res.locals` if downstream handlers need it.
See [sessions and frameworks](references/sessions-and-frameworks.md) for the Qwik
expiry guard, form fields, SvelteKit actions and client helpers, Express error
handling, and the `setup-fw-integration` scaffold command.
## Adapter and logger contracts
Return plain JavaScript objects from adapter methods and normalize ORM-specific
values, including serialized timestamps to `Date` on reads. Official adapters
must implement the full `Adapter` interface and pass the shared adapter test suite.
Configuring `logger` makes Auth.js ignore the top-level `debug` option.