detect device in server component
Answered
llamasad posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/578366504123498496/59421075694632b14a9cc400890b42b2.webp?size=256)
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
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
btw you shouldn't crosspost https://discord.com/channels/752553802359505017/752647196419031042/1161150672624951326
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
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() })
Answer
![Avatar](https://cdn.discordapp.com/avatars/578366504123498496/59421075694632b14a9cc400890b42b2.webp?size=256)
llamasadOP
tks i got it