[GH-ISSUE #990] Incorrect usage of Session types... #25861

Closed
opened 2026-04-17 16:09:19 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @t3duk on GitHub (Dec 22, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/990

I believe that there has been an issue when creating the exported Session type from better-auth/types or how it has been documented / example code created.

My editor says that the Session type is as follows:

type Session = {
    id: string;
    createdAt: Date;
    updatedAt: Date;
    userId: string;
    expiresAt: Date;
    token: string;
    ipAddress?: string | null | undefined;
    userAgent?: string | null | undefined;
}

However, in the documentation here, the Middleware code example tries to satisfy the session object with the Session type - but this is incorrect as the session contains properties of user and session. For example, when using this example code session.user.id will return the user ID, but a type error is given.

In another part of the documentation here it states the Session type DOES include the two user and session properties.

I believe the solution for this would be to change the documentation in the Middleware so that the type of response is the same of auth.$Infer.Session.

Thoughts?

Originally created by @t3duk on GitHub (Dec 22, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/990 I believe that there has been an issue when creating the exported `Session` type from `better-auth/types` or how it has been documented / example code created. My editor says that the `Session` type is as follows: ``` type Session = { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; } ``` However, in the documentation [here](https://www.better-auth.com/docs/integrations/next#middleware), the Middleware code example tries to satisfy the `session` object with the `Session` type - but this is incorrect as the `session` contains properties of `user` and `session`. For example, when using this example code `session.user.id` will return the user ID, but a type error is given. In another part of the documentation [here](https://www.better-auth.com/docs/concepts/typescript#inferring-types) it states the `Session` type DOES include the two `user` and `session` properties. I believe the solution for this would be to change the documentation in the Middleware so that the type of response is the same of `auth.$Infer.Session`. Thoughts?
GiteaMirror added the locked label 2026-04-17 16:09:19 -05:00
Author
Owner

@Bekacru commented on GitHub (Dec 22, 2024):

Yeah you're right. The middleware doc should be updated.

<!-- gh-comment-id:2558504785 --> @Bekacru commented on GitHub (Dec 22, 2024): Yeah you're right. The middleware doc should be updated.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25861