diff --git a/apps/next/utils/logRequest.ts b/apps/next/utils/logRequest.ts index 812942047..08b5a91ef 100644 --- a/apps/next/utils/logRequest.ts +++ b/apps/next/utils/logRequest.ts @@ -1,9 +1,10 @@ import type { GetServerSidePropsContext } from 'next' export function logRequest(ctx: GetServerSidePropsContext) { - console.log( - `${ctx.req.url} - ${ctx.req.headers['user-agent']}${ - ctx.req.headers['x-forwarded-for'] ? ` - ${ctx.req.headers['x-forwarded-for']}` : '' - }` - ) + const ip = + (ctx.req.headers['cf-connecting-ip'] || + ctx.req.headers['x-forwarded-for'] || + ctx.req.socket.remoteAddress) ?? + '' + console.log(`${ctx.req.url} - ${ctx.req.headers['user-agent']} - ${ip}`) } diff --git a/packages/api/src/trpc.ts b/packages/api/src/trpc.ts index e5b9620d6..a6ac58e28 100644 --- a/packages/api/src/trpc.ts +++ b/packages/api/src/trpc.ts @@ -5,17 +5,18 @@ import type { CreateNextContextOptions } from '@trpc/server/adapters/next' import superJson from 'superjson' export const createTRPCContext = async (opts: CreateNextContextOptions) => { - console.log( - `${opts.req.url} - ${opts.req.headers['user-agent']}${ - opts.req.headers['x-forwarded-for'] ? ` - ${opts.req.headers['x-forwarded-for']}` : '' - }` - ) + const ip = + (opts.req.headers['cf-connecting-ip'] || + opts.req.headers['x-forwarded-for'] || + opts.req.socket.remoteAddress) ?? + '' + console.log(`${opts.req.url} - ${opts.req.headers['user-agent']} - ${ip}`) // if there's auth cookie it'll be authenticated by this helper const supabase = createPagesServerClient(opts) - // native sends these instead of cookie auth if (opts.req.headers.authorization && opts.req.headers['refresh-token']) { + // native sends these instead of cookie auth const accessToken = opts.req.headers.authorization.split('Bearer ').pop() const refreshToken = opts.req.headers['refresh-token'] if (accessToken && typeof refreshToken === 'string') {