Security: the panel and the admin are authorised on the server, and payments really work
Next.js 16.4.6, a server-only data access layer for the panel and the admin, Stripe and Polar webhooks that are no longer rejected or duplicate credits, and a presigned upload that accepts real files.
This is a security release, but it ships as a minor and not as a patch: it adds new pieces and changes some internal APIs your code may be using. The structure of the project does not change. Read "If you already have a project" before updating.
Next.js 16.4.6
next, @next/third-parties and eslint-config-next move from 16.4.3 to 16.4.6, pinned to the
exact version. next build now refuses 16.4.3 as vulnerable, so a project on 2.1.4 stops building
until it updates.
The panel and the admin were only protected in the browser
The /dashboard and /admin layouts redirected on the client: the panel's HTML was sent to anyone,
and access depended on every endpoint checking the session by itself. There are now two layers, as
the Next.js authentication guide recommends:
- An optimistic check in the proxy. Without a session cookie,
/dashboard*and/admin*answer 307 to sign-in withcallbackUrl. It only looks at the cookie, never at the database. - The real check in a data access layer (
src/lib/auth/dal.ts, markedserver-only):getCurrentUser(),requireSession()andrequireAdmin(). The session is read once per render, and callers get a narrow user (id, name, email, role, image), never the session with its token. AuthGateandAdminGateinside each layout's Suspense boundary,requireAdmin()in every admin page, andcreateAdminAction()for admin Server Actions.- A test that reads every admin page and fails if one queries data before checking the role.
Sign-in also takes you back to the page you came from (callbackUrl), validated against open
redirects with the same rule as Better Auth.
Payments: what did not work as documented
- Stripe and Polar webhooks got a 403 in production, because they arrive without
Originand the proxy refused them. They are now exempt by exact path; their signature proves they are real. - Polar read every field as
undefined: the SDK delivers them in camelCase and the code looked for snake_case. Subscriptions were not saved and purchases granted no credits. subscription.canceledno longer takes access away. Polar sends it when the customer schedules the cancellation; access stays until the end of the paid period, and onlysubscription.revokedremoves it.- A retried webhook no longer duplicates payments or credits: purchase, payment and credits are written in a single transaction, and a refund that arrives before its payment is no longer lost.
- With the Stripe API version the boilerplate pins, no subscription payment was being recorded. The new invoice fields are now read.
- The "payments not configured" warning no longer shows with Polar configured.
Uploads
The presigned URL carried the checksum of an empty body, so S3 refused every real file. It now also
signs the file's type and size, and POST /api/upload/presigned-url validates its body with a 5 MB
limit.
If you already have a project
Six changes can break code you wrote on top of the boilerplate:
POST /api/upload/presigned-urlrequiressizeand an imagecontentType.src/lib/actions/create-action.tsis no longer'use server': your actions go in their own file.requireAdminis imported from@/lib/auth/daland returns the user, not the session.- With Stripe, chat credits need
STRIPE_SECRET_KEY, andisStripeConfiguredandisPolarConfiguredare no longer exported from@/config/env. - The signatures of
handleWebhookEventandhandlePolarWebhookEventchange, if you call them. - The Prisma client,
auth/serverand the other server modules areserver-only: your scripts outside Next.js need their own Prisma client.
Start by moving Next to 16.4.6. The full list of files to copy, with the diff for each change, is in
"Upgrading from 2.1.4" in the repository's CHANGELOG.md; copied as listed onto an unchanged 2.1.4,
it passes typecheck, lint and tests. Then run bun run test: the admin pages test will tell you
which of yours do not check the role.
No migrations and no new environment variables.