Skip to content
Back to skills

Authjs Knowledge Patch

ASecurity

Auth.js

  • 25 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added May 27, 2026
developmentjavascriptrustjavanextjsnodeexpressgitapidatabasesecurity

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill authjs-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Authjs Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Authjs Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-authjs-knowledge-patch/badge)](https://www.skillsdirectory.com/skills/nevaberry-authjs-knowledge-patch)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: authjs-knowledge-patch
description: Auth.js
version: "5.0.0"
license: MIT
metadata:
  author: Nevaberry
---


# Auth.js Knowledge Patch

Use this skill when configuring Auth.js providers, sessions, adapters, framework
integrations, or operational upgrades. Load the relevant reference for full
examples and configuration details.

| Reference | Topics |
| --- | --- |
| [Providers and Authentication](references/providers-and-authentication.md) | OAuth checks and account fields, Credentials, email providers, experimental Passkey setup, account linking, native OAuth clients |
| [Sessions and Framework Integrations](references/sessions-and-frameworks.md) | JWT and database sessions, magic-link lifecycle, Qwik, SvelteKit, Express, session endpoint caching |
| [Auth.js v5 Migration and Next.js Integration](references/v5-migration.md) | Next.js Proxy runtime and custom Passkey pages |
| [Adapters, Operations, and Security](references/adapters-operations-and-security.md) | Token parsing, host precedence, CommonJS, security updates, corporate proxies, token refresh, adapters, framework scaffolding, logging |
| [Better Auth Transition](references/better-auth-transition.md) | Maintenance and project choice |

## Upgrade and compatibility checks

### OAuth check cookies 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 it through the same path as a missing token.

### Host precedence and CommonJS

In trusted-host mode, an explicit `NEXTAUTH_URL` takes precedence over the host
auto-detected from forwarded headers.

The 4.24.15 release uses `uuid@^11.1.1`, restoring support for loading `next-auth`
via `require()` on Node.js versions earlier than 20.19.

### Package-specific fixes

`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` authorization callback parameter.

`@auth/kysely-adapter@1.11.2` requires `kysely@^0.28.15` to address CVE-2026-33468.
When upgrading the adapter, update the application's `kysely` dependency and
lockfile to satisfy that range.

Upgrade to `@auth/sveltekit@1.11.1` or later for the Nodemailer security fix.

### Next.js Proxy runtime

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 that requires Node.js.

```ts
// proxy.ts
export { auth as proxy } from "./auth"
```

### Maintenance and project choice

Better Auth now maintains Auth.js (NextAuth.js), with 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.

## Authentication configuration

### Credentials failures

Returning `null` from `authorize` redirects to sign-in with
`?error=CredentialsSignin&code=credentials` when using the built-in pages.
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 providers and magic links

Add `ForwardEmail`, `Sendgrid`, `Postmark`, or `Mailgun` to `providers` and set the
matching key: `AUTH_FORWARDEMAIL_KEY`, `AUTH_SENDGRID_KEY`, `AUTH_POSTMARK_KEY`, or
`AUTH_MAILGUN_KEY`. Their sign-in IDs are `forwardemail`, `sendgrid`, `postmark`,
and `mailgun`, respectively.

The Loops template receives only the case-sensitive data variable `url` for the
magic link. Pass `apiKey` and the template's Transactional ID as `transactionalId`.

Email sign-in applies Unicode NFKC normalization before validating the address.
Several `VerificationToken` rows may be outstanding for one email address. Each
token is single-use and expires after one day by default, configurable through the
email provider's `maxAge` in seconds. Periodically remove expired rows from unfinished sign-ins.

For custom HTTP delivery, configure an `email` provider with a database adapter.
Implement `sendVerificationRequest` to send `url` to `identifier`, and start the
flow with `signIn("http-email", { email })`.

### Apple callbacks

Register the application's Apple callback URL directly and leave
`redirectProxyUrl` unset for Apple.

### Experimental Passkey setup

Use Node.js 20 or later, `@simplewebauthn/server@9.0.3`, and a compatible database
adapter. The 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. In Prisma,
add `Authenticator Authenticator[]` to the existing `User` model and add the
authenticator model shown in the providers reference.

```ts
export default {
  adapter: PrismaAdapter(prisma),
  providers: [Passkey],
  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
`signIn("passkey", { action: "register" })` for signed-in users adding a passkey
and `signIn("passkey")` for signed-out users.

## Accounts and sessions

### OAuth account storage and linking

By default, Auth.js stores `access_token`, `expires_at`, `refresh_token`,
`id_token`, `token_type`, `scope`, and `session_state` when supplied by the provider.
Use the provider's `account()` callback to choose persisted token fields; add
matching adapter schema columns for any extra fields returned.

To link a second OAuth account with the same email, sign in to the existing user
first, then sign in with the second provider. Manual unlinking requires an adapter
implementing `unlinkAccount`.

Auth.js runs OAuth on the server as a confidential client. Native mobile and
desktop apps that run OAuth directly need a public-client flow.

### Session storage and expiry

With an adapter for user and account storage, explicitly select
`session: { strategy: "jwt" }` to omit the database `Session` model.
On database-session reads, Auth.js checks `expires` and deletes expired rows.
Session cookies exceeding roughly 4 KB per cookie are split and reassembled on
read. GET requests to the session endpoint include headers preventing caching
by default.

### Refreshing provider tokens with database sessions

In `callbacks.session({ session, user })`, find the provider account using
`user.id` and compare `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

### Qwik

Export `onRequest`, `useSession`, `useSignIn`, and `useSignOut` from `QwikAuth$`
in `src/routes/plugin@auth.ts`. Read `useSession().value` in components or
`event.sharedMap` in page/layout request handlers. Pass the sign-in and sign-out
hooks' return values to Qwik City's `<Form>`. Sign-in fields use `providerId`
and `options.redirectTo`; sign-out uses the top-level `redirectTo` field.

### SvelteKit

Re-export the `SvelteKitAuth` handle from `hooks.server.ts` to expose
`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. Change destinations with `signInPage` and `signOutPage`,
set the post-sign-in destination with `SignIn`'s `options.redirectTo`, or use the
request-based helpers from `@auth/sveltekit/client`.

### Express

Mount `ExpressAuth(authConfig)` under `/auth` for endpoints such as `/auth/signin`
and `/auth/signout`. Use `getSession` from `@auth/express` with the incoming request
and the same config; store the session on `res.locals` if downstream handlers need it.

## Adapter and operational configuration

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.

Use a provider's `[customFetch]` for OAuth requests through a corporate proxy.
With Undici, pass a `ProxyAgent` as the fetch dispatcher.
When `logger` is configured, Auth.js ignores the top-level `debug` option.

To scaffold a framework integration, run the monorepo's
`npm run setup-fw-integration -- my-framework` script.
The main module needs a named export; the deployed example lives under
`apps/examples/<framework-name>`.

Files in this skill

  • SKILL.md3.3 KB
  • references/authentication-patterns.md2.1 KB
  • references/configuration.md2.1 KB
  • references/providers-and-features.md808 B
  • references/v5-migration.md969 B
  • references/webauthn-passkeys.md2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.