Using `userAgent` in Next.js App Router — Device, Browser, OS & Bot Detection

typescript dev.to

Server-side user-agent parsing without the manual string gymnastics. Ever needed to redirect mobile users or block bots before the page even renders? Next.js has a built-in helper for exactly that: userAgent. Instead of manually parsing raw header strings, you get a clean structured object with everything you need, right inside Middleware or a Route Handler. What is userAgent? userAgent is a helper exported from next/server. Pass it the incoming NextRequest and it returns a parsed object wi

Read Full Tutorial open_in_new
arrow_back Back to Tutorials