[GH-ISSUE #821] Add Location Plugin #8452

Closed
opened 2026-04-13 03:31:17 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @BayBreezy on GitHub (Dec 8, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/821

This feature request is not related to any issues reported in the repo.

I found myself using the geoip-lite package to attach the user's location to their session.

I followed the instructions here Customizing Session response to add the location to the current session.

customSession(async ({ user, session }) => {
      let location = "Unknown location";
      if (session.ipAddress) {
        const res = geoIp.lookup(session.ipAddress);
        if (res) location = `${res.city} ${res.region} ${res.country}`;
      }
      return {
        user,
        session: {
          ...session,
          location: location || undefined,
        },
      };
})

I was under the impression that the location variable would have been added to the list of sessions from the /list-sessions endpoint as well but it was not there.

Describe the solution you'd like
I would for a plugin to exist that adds the location object from geoip-lite to the current session and all listed sessions

Describe alternatives you've considered
An alternative would just be to add an example of how to accomplish this to the docs.
I tried creating a custom plugin that uses an after hook to modify the response body but the body keeps coming back as undefined so i cant directly modify the list of sessions that is returned to the client.

Additional context
I tried hooking into both the before and after and the body was still undefined.

Originally created by @BayBreezy on GitHub (Dec 8, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/821 This feature request is not related to any issues reported in the repo. I found myself using the [geoip-lite](https://www.npmjs.com/package/geoip-lite) package to attach the user's location to their session. I followed the instructions here [Customizing Session response](https://www.better-auth.com/docs/concepts/session-management#customizing-session-response) to add the location to the current session. ```ts customSession(async ({ user, session }) => { let location = "Unknown location"; if (session.ipAddress) { const res = geoIp.lookup(session.ipAddress); if (res) location = `${res.city} ${res.region} ${res.country}`; } return { user, session: { ...session, location: location || undefined, }, }; }) ``` I was under the impression that the `location` variable would have been added to the list of sessions from the `/list-sessions` endpoint as well but it was not there. **Describe the solution you'd like** I would for a plugin to exist that adds the location object from geoip-lite to the current session and all listed sessions **Describe alternatives you've considered** An alternative would just be to add an example of how to accomplish this to the docs. I tried creating a custom plugin that uses an after hook to modify the response body but the body keeps coming back as `undefined` so i cant directly modify the list of sessions that is returned to the client. **Additional context** I tried hooking into both the before and after and the body was still undefined.
GiteaMirror added the locked label 2026-04-13 03:31:17 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 12, 2025):

Hi, @BayBreezy. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • You requested a new plugin to integrate location data from the geoip-lite package into user sessions.
  • The integration is specifically for the /list-sessions endpoint.
  • You encountered issues with the response body being undefined when attempting a custom implementation.
  • Suggested providing documentation to help users implement this feature themselves.
  • No further activity or comments have been made on this issue.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If there is no response, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:2967417608 --> @dosubot[bot] commented on GitHub (Jun 12, 2025): Hi, @BayBreezy. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - You requested a new plugin to integrate location data from the geoip-lite package into user sessions. - The integration is specifically for the `/list-sessions` endpoint. - You encountered issues with the response body being undefined when attempting a custom implementation. - Suggested providing documentation to help users implement this feature themselves. - No further activity or comments have been made on this issue. **Next Steps:** - Please let me know if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If there is no response, this issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@reslear commented on GitHub (Jun 19, 2025):

not stale

<!-- gh-comment-id:2989100242 --> @reslear commented on GitHub (Jun 19, 2025): not stale
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8452