Next.js Discord

Discord Forum

detect device in server component

Answered
llamasad posted this in #help-forum
Open in Discord
Avatar
Is there any way to detect the user device in server component i using app router
Answered by risky
But for others looking here, you said that this worked for you:
import { userAgent } from "next/server"


and based on [docs](https://nextjs.org/docs/messages/middleware-user-agent), i would assume that this would work: (but in theory should also be able to use headers and parse manually)
import { userAgent } from "next/server"
import { headers } from "next/headers"

const ua = userAgent({ headers: headers() })
View full answer

3 Replies

Avatar
But for others looking here, you said that this worked for you:
import { userAgent } from "next/server"


and based on [docs](https://nextjs.org/docs/messages/middleware-user-agent), i would assume that this would work: (but in theory should also be able to use headers and parse manually)
import { userAgent } from "next/server"
import { headers } from "next/headers"

const ua = userAgent({ headers: headers() })
Answer
Avatar
tks i got it