[GH-ISSUE #6537] OpenAPI for /get-session should mark 200 response as nullable #19177

Closed
opened 2026-04-15 17:59:10 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @hai-trung-le on GitHub (Dec 5, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6537

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I'm using Better Auth 1.4.5 with the official OpenAPI plugin, and the response format of 200 status code for /get-session is described as

"200": {
  "description": "Success",
  "content": {
    "application/json": {
      "schema": {
        "type": "object",
        "properties": {
          "session": {
            "$ref": "#/components/schemas/Session"
          },
          "user": {
            "$ref": "#/components/schemas/User"
          }
        },
        "required": [
          "session",
          "user"
        ]
      }
    }
  }
}

However, when no session is found or invalid session, the endpoint returns 200 with a null body, contradicting the OpenAPI response.

Current vs. Expected behavior

OpenAPI schema should make the 200 response of /get-session nullable.

What version of Better Auth are you using?

1.4.5

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 10 Pro"
  },
  "node": {
    "version": "v24.11.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "^15.5.7"
    },
    {
      "name": "react",
      "version": "^19.2.1"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "^1.4.5",
    "config": null
  }
}

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
  },
  plugins: [
    bearer(),
    openAPI(),
  ],
});

Additional context

No response

Originally created by @hai-trung-le on GitHub (Dec 5, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6537 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I'm using Better Auth 1.4.5 with the official OpenAPI plugin, and the response format of 200 status code for `/get-session` is described as ```json "200": { "description": "Success", "content": { "application/json": { "schema": { "type": "object", "properties": { "session": { "$ref": "#/components/schemas/Session" }, "user": { "$ref": "#/components/schemas/User" } }, "required": [ "session", "user" ] } } } } ``` However, when no session is found or invalid session, the endpoint returns 200 with a null body, contradicting the OpenAPI response. ### Current vs. Expected behavior OpenAPI schema should make the 200 response of `/get-session` nullable. ### What version of Better Auth are you using? 1.4.5 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 10 Pro" }, "node": { "version": "v24.11.1", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "next", "version": "^15.5.7" }, { "name": "react", "version": "^19.2.1" } ], "databases": null, "betterAuth": { "version": "^1.4.5", "config": null } } ``` ### 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 }, plugins: [ bearer(), openAPI(), ], }); ``` ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-15 17:59:10 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 5, 2025):

Thanks for reporting this! It looks like when no session is found, the endpoint returns a 200 with a null body, which conflicts with the OpenAPI schema definition that mandates a session and user object. In our recent discussions, we’ve seen that the return type for getSession should indeed be marked as nullable [1]. I recommend updating the openAPI plugin to mark the get-session response as nullable so that it accurately reflects the possibility of a null value when no session exists. This should help ensure that the generated types correctly allow a null response.

Tag @better-auth-agent if you would like an answer from the Agent. Do you have any further questions on this issue or other aspects of the API?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3615209180 --> @better-auth-agent[bot] commented on GitHub (Dec 5, 2025): Thanks for reporting this! It looks like when no session is found, the endpoint returns a 200 with a null body, which conflicts with the OpenAPI schema definition that mandates a session and user object. In our recent discussions, we’ve seen that the return type for getSession should indeed be marked as nullable [[1]](https://github.com/better-auth/better-auth/issues/6446). I recommend updating the openAPI plugin to mark the get-session response as nullable so that it accurately reflects the possibility of a null value when no session exists. This should help ensure that the generated types correctly allow a null response. Tag @better-auth-agent if you would like an answer from the Agent. Do you have any further questions on this issue or other aspects of the API? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@GautamBytes commented on GitHub (Dec 5, 2025):

Working on it!!

<!-- gh-comment-id:3615847766 --> @GautamBytes commented on GitHub (Dec 5, 2025): Working on it!!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19177