IP address not saved #976

Closed
opened 2026-03-13 08:13:53 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @AnasSahel on GitHub (Apr 4, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Hello, I'm not able to get the IP address of the user when I sign him/her up.

  1. I'm using better-auth with Next.js.
  2. I followed the installation and configuration steps from better-auth documentation
  3. I have the plugin nextCookies() enabled
  4. Here's my call
const { token, user } = await auth.api.signUpEmail({
    body: {
      name,
      email,
      password,
    },
    headers: await headers(),
  });
  1. Locally or in Vercel, the IP address is not register neither the user-agent
Image

Current vs. Expected behavior

I'm expecting the fields ip_address and user_agent to be filled with the right value

What version of Better Auth are you using?

1.2.5

Provide environment information

- OS : ["macOS", "Vercel"]
- Browsers : ["Edge"]

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { db } from "@/db";
import { account, session, user, verification } from "@/db/schema/auth";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { nextCookies } from "better-auth/next-js";

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    schema: {
      user,
      session,
      account,
      verification,
    },
  }),
  plugins: [
    nextCookies(), // should be the last plugin in the array. It makes Set-Cookie work in Next.js
  ],
  emailAndPassword: {
    enabled: true,
  },
  advanced: {
    ipAddress: {
      ipAddressHeaders: [
        "x-forwarded-for",
        "x-vercel-forwarded-for",
        "x-real-ip",
      ],
      disableIpTracking: false,
    },
  },
});

Additional context

No response

Originally created by @AnasSahel on GitHub (Apr 4, 2025). ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce Hello, I'm not able to get the IP address of the user when I sign him/her up. 1. I'm using `better-auth` with `Next.js`. 2. I followed the installation and configuration steps from `better-auth` documentation 3. I have the plugin `nextCookies()` enabled 4. Here's my call ``` const { token, user } = await auth.api.signUpEmail({ body: { name, email, password, }, headers: await headers(), }); ``` 5. Locally or in `Vercel`, the `IP address` is not register neither the `user-agent` <img width="1288" alt="Image" src="https://github.com/user-attachments/assets/4ac6dc5c-cc00-4ef4-bdae-07177d74bad7" /> ### Current vs. Expected behavior I'm expecting the fields ip_address and user_agent to be filled with the right value ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash - OS : ["macOS", "Vercel"] - Browsers : ["Edge"] ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { db } from "@/db"; import { account, session, user, verification } from "@/db/schema/auth"; import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { nextCookies } from "better-auth/next-js"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema: { user, session, account, verification, }, }), plugins: [ nextCookies(), // should be the last plugin in the array. It makes Set-Cookie work in Next.js ], emailAndPassword: { enabled: true, }, advanced: { ipAddress: { ipAddressHeaders: [ "x-forwarded-for", "x-vercel-forwarded-for", "x-real-ip", ], disableIpTracking: false, }, }, }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 08:13:53 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Apr 4, 2025):

fix - #2121

@Kinfe123 commented on GitHub (Apr 4, 2025): fix - #2121
Author
Owner

@jpainam commented on GitHub (Jul 9, 2025):

Having the same issue. userAgent is saved, but not ipAddress on localhost, i tried connecting in my local network. same issue. Did you solve it @AnasSahel

@jpainam commented on GitHub (Jul 9, 2025): Having the same issue. `userAgent` is saved, but not `ipAddress` on localhost, i tried connecting in my local network. same issue. Did you solve it @AnasSahel
Author
Owner

@AnasSiddiqui18 commented on GitHub (Aug 8, 2025):

The reason the ip address is not storing is because on localhost we got an ip something like this ::1 and better-auth is not storing it, so we have to add a condition like this

            const ip = header_res.get('x-forwarded-for')!;

            const _response = await auth.api.signInEmail({
                body: {
                    email,
                    password,
                },

                headers: new Headers({
                    'x-forwarded-for': ip === '::1' ? '127.0.0.1' : ip,
                }),
            });
@AnasSiddiqui18 commented on GitHub (Aug 8, 2025): The reason the ip address is not storing is because on localhost we got an ip something like this ::1 and better-auth is not storing it, so we have to add a condition like this ```ts const ip = header_res.get('x-forwarded-for')!; const _response = await auth.api.signInEmail({ body: { email, password, }, headers: new Headers({ 'x-forwarded-for': ip === '::1' ? '127.0.0.1' : ip, }), }); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#976