get user ip in trpc

I know https://www.answeroverflow.com/m/1097080265928609802 in here the question is already answered but i get value in ip as ::ffff:127.0.0.1 this instead of real ip here is how I do that
export const createTRPCContext = async (opts: CreateNextContextOptions) => {
const { req, res } = opts

let ip = req.headers['x-forwarded-for'] as string
const session = await getServerAuthSession({ req, res })

return createInnerTRPCContext({
session,
ip
})
}
export const createTRPCContext = async (opts: CreateNextContextOptions) => {
const { req, res } = opts

let ip = req.headers['x-forwarded-for'] as string
const session = await getServerAuthSession({ req, res })

return createInnerTRPCContext({
session,
ip
})
}
and when I make request I receive in response that ::ffff:127.0.0.1 thats testing response
.mutation(async ({ ctx }) => {
return { success: true, ip: ctx.ip }
})
.mutation(async ({ ctx }) => {
return { success: true, ip: ctx.ip }
})
1 Reply
whatplan
whatplan10mo ago
well your testing a local dev server from your local computer so to your server 127.0.0.1 (local host) is you correct ip try deploying and accessing from your phone