My place in the WordPress community
- I have had a wordpress.org account since 2006.
- I contributed to WordPress core for versions 7.0 and 7.1.
- I maintain 30 plugins on wordpress.org.
- I organise and speak at WordCamps.
- I have attended every WordCamp Europe from 2017 to 2026.
- Local WordPress meetup: WordPress Stockholm
Adding BankID to a Next.js application is not a login component. It is a server-side order flow with a certificate, a polling loop and strict rules about what the browser may see. I am not part of BankID and not a lawyer. This page follows the official BankID developer documentation, mainly the OpenAPI specification of the relying party API, and shows where each step belongs in the Next.js App Router.

The main hall of Stockholm Central Station. Photo: Ezarate, CC BY-SA 4.0, Wikimedia Commons.
How does the BankID order flow work?
The specification for the Relying Party API v6.0 lists a test server at https://appapi2.test.bankid.com/rp/v6.0 and a production server at https://appapi2.bankid.com/rp/v6.0. Only HTTP POST is allowed. The main endpoints are /auth for identification, /sign for signing, /collect to read the result, /cancel to stop an order, plus payment and phone variants.
The flow has four steps:
- Your server calls
/author/sign. The response holdsorderRef,autoStartToken,qrStartTokenandqrStartSecret. - The user starts the BankID app, either by autostart on the same device or by scanning an animated QR code from another device.
- Your server calls
/collectwith theorderRef. The status ispending,completeorfailed. - On
complete, the response carries the user’s identity. Your application creates its own session.
The developer site has separate use-case pages for Mobile BankID on the same device and on another device. A visitor who opens your page on a phone takes the first path, a visitor on a desktop takes the second. Your Next.js page has to support both.
Where does the BankID call live in Next.js?
Not in the browser. The specification returns 401 or 403 with the text “You do not have access to the service” when the caller is not authorised, and the developer site has pages on requesting a certificate and creating a PKCS#12 file for it. I did not read those two pages in full, so I do not describe the certificate steps here. What matters for the architecture: the call is authenticated with something that must stay on the server.
A Route Handler in app/api/bankid/start/route.ts is the natural place. Route Handlers support POST and read cookies through next/headers. Pin the Node runtime, because the Route Handler docs list runtime = 'nodejs' as a segment option:
// app/api/bankid/start/route.ts
import { headers } from 'next/headers'
import { bankid } from '@/lib/bankid-client'
export const runtime = 'nodejs'
export async function POST() {
const h = await headers()
const endUserIp = h.get('x-forwarded-for')?.split(',')[0]?.trim() ?? ''
const order = await bankid('/auth', { endUserIp })
// order: orderRef, autoStartToken, qrStartToken, qrStartSecret
return Response.json({ orderRef: order.orderRef, autoStartToken: order.autoStartToken })
}bankid() is your small wrapper that posts JSON to the server URL with the client certificate. The x-forwarded-for header in this sketch is an assumption about your hosting. The specification only says what endUserIp must be.
What must endUserIp contain?
The specification says it is the IP address of the end user as your service sees it, IPv4 or IPv6, and that you must make sure it is the address of the end user’s device and “not the internal address of any reverse proxy” between you and the user. If you request a risk indication with returnRisk, the specification says the risk indication requires a correct endUserIp.
In a Next.js deployment behind a CDN and a load balancer, the left-most value of a forwarded-for header is not always the client. Test it in staging with a real phone on mobile data and a laptop on Wi-Fi, and log what BankID reports back in completionData.device.ipAddress. The specification says that when an order is started with the autostart token you can compare that address with the one your service observed, as a check against session fixation.
How do I poll collect without hammering the API?
The specification states that the service should keep calling collect every two seconds while the status is pending, and must abort when the status is failed. I keep that loop behind one server-side status endpoint that your page polls, so the browser never talks to BankID:
// app/api/bankid/status/route.ts
import { cookies } from 'next/headers'
import { bankid } from '@/lib/bankid-client'
import { createSession } from '@/lib/session'
export async function POST(req: Request) {
const { orderRef } = await req.json()
const result = await bankid('/collect', { orderRef })
if (result.status === 'complete') {
await createSession(result.completionData.user.personalNumber)
return Response.json({ status: 'complete' })
}
return Response.json({ status: result.status, hintCode: result.hintCode })
}The client polls this route every two seconds and shows a message per hintCode. A real build also checks that the orderRef belongs to the current browser, for example through a short-lived cookie set when the order started. That cookie is set in the start Route Handler, where the cookies documentation says setting cookies is allowed.
Which hint codes does the interface need?
While an order is pending, the specification tells you to use the hintCode to give the user details and to keep calling collect. The pending codes in the specification are outstandingTransaction, noClient, started, userMrtd, userCallConfirm, userSign, processing, userStepUp and userFace. The failed codes include expiredTransaction, certificateErr, userCancel, cancelled, startFailed, userDeclinedCall and notSupportedByUserApp.
Each code names the action your service takes and the recommended user message. For outstandingTransaction the specification points to message RFA13 if you tried to launch the app automatically and RFA1 if the user must start it. For expiredTransaction it says you must inform the user and use message RFA8. The developer site publishes the recommended texts on its user messages page. Use those texts, and put them in a translation file so Swedish and English both work.
How do the return URL and the QR code fit in?
For orders started on the same device, the specification says the returnUrl is called when the order completes. It should contain a nonce for the session, and when the user returns, your service should verify that the order completed successfully and that the device receiving the returnUrl is the one that started the order. It adds that you should make sure the cookie or user IP address has not changed between the start page and the return page.
In Next.js that maps to a returnUrl pointing at a route in your app, with the nonce in the fragment as the specification’s example shows, and a cookie that the start handler set. The check runs on the server.
The response of /auth also carries qrStartToken and qrStartSecret, which the specification says are used to compute the animated QR code. The developer site has a how-to guide on QR codes. I follow that guide for where the code is computed and refreshed. The developer news also records that support for static QR codes ended with version 6, so a printed or static QR image is not an option.
How does signing differ from login?
/sign takes the same endUserIp, and requires userVisibleData. The text is shown to the user in the BankID app and, per the specification, must be UTF-8 encoded and then base 64 encoded, and the encoded value is limited to 1500 characters. A userVisibleDataFormat of simpleMarkdownV1 allows simple formatting. In the collect response the completionData holds a base 64 encoded XML signature and an ocspResponse, which the specification describes as a signed OCSP response with a nonce.
In an App Router app, build userVisibleData on the server from the record the user is signing, never from a string the browser sends. What the user sees in the BankID app must match what your database stores.
const userVisibleData = Buffer.from(
`Agreement ${agreement.id}\nTotal: ${agreement.total}`,
'utf8'
).toString('base64')How do I turn a BankID result into a Next.js session?
Once collect returns complete, your application owns the session. The Next.js authentication guide recommends setting session cookies on the server with HttpOnly, Secure, SameSite, an expiry and a path, and keeping the payload to minimal unique user data. It says the payload should not contain personally identifiable information. A Swedish personal number is exactly that, so I store an internal user ID in the session and keep the personal number in the database.
The same guide recommends a data access layer that verifies the session close to the data, not a check in a layout, because layouts do not re-render on every navigation. A BankID login changes nothing about that rule.
What goes wrong most often?
- Calling the BankID API from a Server Component that runs at build time or gets cached. Orders are per request, so keep them in Route Handlers or Server Functions.
- Trusting an
orderRefposted by the browser without tying it to the session that started it. - Showing one generic error for every failed hint code.
- Testing only on desktop. The same-device flow with a return URL behaves differently from the QR flow.
Where does a BankID integration start?
BankID publishes a test portal with pages on configuring a BankID for test and on testing identification and signing. An integration starts there, before a production certificate matters. For BankID login or signing in a Next.js app, send the scope through the contact page and say whether you need identification, signing or both. The estimate I send back first is written and free. The wider offer sits on the Next.js developer page.
Selected projects
Examples of my work.
Jobsin.co - International Job Platform for Technical Specialists
Jobsin.co is a modern job board focused on posting job offers for qualified specialists in the fields of construction, mechanics, and engineering worldwide.
KTS Conference Mobile App - Event Management Application for iOS and Android
The event application project dedicated to the 15th Broadband Technology Conference is a WordPress-based event site with editable content and event-management features for conference participants.
LEARNETIC - E-publishing Platform | WPPoland
Effective e-Publishing is an innovative project focused on digital content creation, import, publishing, and distribution. This platform is designed for effe...
See also in Sweden
Need this service: Next.js developer in Stockholm?
Describe your project by e-mail. I reply within 24 hours.
Describe your projectExplore other WordPress services and knowledge base
Migration to Astro, Next.js, and headless WordPress.
WooCommerce sync with ERP and wholesale systems.
Business process automation around WordPress and company systems.
Library of concrete automation use cases.
Headless WordPress, Sanity, Strapi, and Contentful with Astro or Next.js.
Astro, MDX, edge delivery, and Core Web Vitals measured on real traffic.
Custom WordPress engineering and architecture.
Scalable headless, ERP, and AI architecture for enterprise.
Related categories
Supporting articles

Six to sixteen weeks for typical engagements, with a four-phase shape: discovery, scoping, build and cutover, tuning. The variables are catalogue size, integration count, URL preservation, and editorial team readiness, not framework choice.

A definitive 4-year Total Cost of Ownership (TCO) analysis, real-world Core Web Vitals benchmarks, Astro 7 GraphQL APQ architecture, and a 10-point executive decision matrix for choosing between decoupled and traditional WordPress.

The Shopify Plus vs WooCommerce headless decision in 2026 is no longer a binary "platform vs custom" trade-off. Both can run headless, both integrate AI, both ship at the edge. The real axes are control, total cost over five years, and exit strategy. This article walks the matrix with confirmed platform facts.