Next.js Discord

Discord Forum

detect device in server component

Answered
llamasad posted this in #help-forum
Open in Discord
Avatar
llamasadOP
Is there any way to detect the user device in server component i using app router
Answered by Risky did start the fire 🙃
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
Risky did start the fire 🙃
Avatar
Risky did start the fire 🙃
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
llamasadOP
tks i got it