[GH-ISSUE #2958] internalAdapter.createSession does not map to options.session.fields #18044

Closed
opened 2026-04-15 16:23:46 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @gregg-cbs on GitHub (Jun 9, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2958

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Setup better auth with a config that maps session fields to custom field names:
const auth = betterAuth({
  session: {
    fields: {
      userId: "user_id",
      expiresAt: "expires_at",
      ipAddress: "ip_address",
      userAgent: "user_agent",
      createdAt: "date_created",
      updatedAt: "date_updated", 
      guest: "guest",
    }
  }
})
  1. Create a session via the internalAdapter using ctx.context.internalAdapter.createSession()
  2. Note the response is of fields that are better auths naming i.e. "expiresAt" instead of mapped "expires_at" but the session was stored into the database with correct naming "expires_at" instead of "expiresAt".

Current vs. Expected behavior

I expect the response from createSession() to return the mapped fields seeing as it is storing the session into the DB with the mapped field names but instead it is returning non mapped fields.

What version of Better Auth are you using?

1.2.8

Provide environment information

Windows
Nodejs

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @gregg-cbs on GitHub (Jun 9, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2958 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Setup better auth with a config that maps session fields to custom field names: ``` const auth = betterAuth({ session: { fields: { userId: "user_id", expiresAt: "expires_at", ipAddress: "ip_address", userAgent: "user_agent", createdAt: "date_created", updatedAt: "date_updated", guest: "guest", } } }) ``` 2. Create a session via the internalAdapter using ctx.context.internalAdapter.createSession() 3. Note the response is of fields that are better auths naming i.e. "expiresAt" instead of mapped "expires_at" but the session was stored into the database with correct naming "expires_at" instead of "expiresAt". ### Current vs. Expected behavior I expect the response from createSession() to return the mapped fields seeing as it is storing the session into the DB with the mapped field names but instead it is returning non mapped fields. ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash Windows Nodejs ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 16:23:46 -05:00
Author
Owner

@gregg-cbs commented on GitHub (Jun 9, 2025):

Looks like the adapter findOne does not map the fields either... How do we map the fields then?

await ctx.context.adapter.findOne({
  model: "session",
  where: [{field: "token", value: session.token}]
})
<!-- gh-comment-id:2955728373 --> @gregg-cbs commented on GitHub (Jun 9, 2025): Looks like the adapter findOne does not map the fields either... How do we map the fields then? ```ts await ctx.context.adapter.findOne({ model: "session", where: [{field: "token", value: session.token}] }) ```
Author
Owner

@Kinfe123 commented on GitHub (Jun 9, 2025):

When you use the fields property to map your model fields to custom column names in the database, this only affects the database schem , not the objects returned by the API or used in your app code. but this is something that we will consider as well for future.

<!-- gh-comment-id:2956670570 --> @Kinfe123 commented on GitHub (Jun 9, 2025): When you use the fields property to map your model fields to custom column names in the database, this only affects the database schem , not the objects returned by the API or used in your app code. but this is something that we will consider as well for future.
Author
Owner

@gregg-cbs commented on GitHub (Jun 10, 2025):

Thats a bit silly because now there is a discrepancy in field names depending on how i get the session.

<!-- gh-comment-id:2958609471 --> @gregg-cbs commented on GitHub (Jun 10, 2025): Thats a bit silly because now there is a discrepancy in field names depending on how i get the session.
Author
Owner

@Kinfe123 commented on GitHub (Aug 10, 2025):

Duplicate issue. closing now.

<!-- gh-comment-id:3172832458 --> @Kinfe123 commented on GitHub (Aug 10, 2025): Duplicate issue. closing now.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18044