detect device in server component
Answered
llamasad posted this in #help-forum
llamasadOP
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:
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"
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() })
3 Replies
btw you shouldn't crosspost https://discord.com/channels/752553802359505017/752647196419031042/1161150672624951326
But for others looking here, you said that this worked for you:
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"
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
llamasadOP
tks i got it