listUserTeams causes error if user is not part of any teams #2325

Closed
opened 2026-03-13 09:44:11 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @IshanArya on GitHub (Nov 18, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Create a user in an organization who is not part of any teams then call:

const { data, error } = await authClient.organization.listUserTeams();

Error:

# SERVER_ERROR:  error: syntax error at or near ")"
    at /Users/eos/projects/PharmaOne/node_modules/pg/lib/cl
ient.js:545:17
    at processTicksAndRejections (node:internal/process/tas
k_queues:105:5)
    at PostgresConnection.executeQuery (file:///Users/eos/p
rojects/PharmaOne/node_modules/kysely/dist/esm/dialect/post
gres/postgres-driver.js:90:49)
    at file:///Users/eos/projects/PharmaOne/node_modules/ky
sely/dist/esm/query-executor/query-executor-base.js:35:28
    at DefaultConnectionProvider.provideConnection (file://
/Users/eos/projects/PharmaOne/node_modules/kysely/dist/esm/
driver/default-connection-provider.js:10:20)

Current vs. Expected behavior

This should just return an empty list if user is not part of any teams but throws an error for a bad PG query.

What version of Better Auth are you using?

1.3.34

System info

Nothing is outputed, but this is a MacOS system.

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: [
    organization({
      teams: {
        enabled: true,
      },
})]
});

Additional context

No response

Originally created by @IshanArya on GitHub (Nov 18, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Create a user in an organization who is not part of any teams then call: ``` const { data, error } = await authClient.organization.listUserTeams(); ``` Error: ``` # SERVER_ERROR: error: syntax error at or near ")" at /Users/eos/projects/PharmaOne/node_modules/pg/lib/cl ient.js:545:17 at processTicksAndRejections (node:internal/process/tas k_queues:105:5) at PostgresConnection.executeQuery (file:///Users/eos/p rojects/PharmaOne/node_modules/kysely/dist/esm/dialect/post gres/postgres-driver.js:90:49) at file:///Users/eos/projects/PharmaOne/node_modules/ky sely/dist/esm/query-executor/query-executor-base.js:35:28 at DefaultConnectionProvider.provideConnection (file:// /Users/eos/projects/PharmaOne/node_modules/kysely/dist/esm/ driver/default-connection-provider.js:10:20) ``` ### Current vs. Expected behavior This should just return an empty list if user is not part of any teams but throws an error for a bad PG query. ### What version of Better Auth are you using? 1.3.34 ### System info ```bash Nothing is outputed, but this is a MacOS system. ``` ### 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: [ organization({ teams: { enabled: true, }, })] }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 09:44:11 -05:00
Author
Owner

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

It looks like the error may be occurring because the underlying query isn’t properly handling an empty teams list. As a troubleshooting step, please verify that the user’s membership is being checked before calling listUserTeams. In your code you might add a check or wrap the call in a try/catch to safely return an empty array if no teams are found. It could also be worth checking if a recent patch for organization queries is available that addresses handling of empty team arrays. Tag @better-auth-agent if you would like an answer from the Agent. What additional details can you provide about the context in which the error occurs?

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 18, 2025): It looks like the error may be occurring because the underlying query isn’t properly handling an empty teams list. As a troubleshooting step, please verify that the user’s membership is being checked before calling listUserTeams. In your code you might add a check or wrap the call in a try/catch to safely return an empty array if no teams are found. It could also be worth checking if a recent patch for organization queries is available that addresses handling of empty team arrays. Tag @better-auth-agent if you would like an answer from the Agent. What additional details can you provide about the context in which the error occurs? <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Nov 18, 2025):

Hi @IshanArya! I'm Dosu and I’m helping the better-auth team.

This is a known bug in Better Auth 1.3.34 (and 1.3.29–1.3.34) with PostgreSQL: if a user isn't part of any teams, listUserTeams tries to run a query like id IN (), which causes a syntax error instead of returning an empty list. The root cause is that the backend doesn't handle empty arrays for the IN operator when building the SQL query. This is fixed in internal build 5311 and above, but not in 1.3.34. As a workaround, you can check for team memberships before calling listUserTeams, or filter on the client side if you can't upgrade yet. Upgrading to 5311+ will resolve the issue and return an empty array as expected. More details and related discussion are available here.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Nov 18, 2025): <!-- Greeting --> Hi @IshanArya! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known bug in Better Auth 1.3.34 (and 1.3.29–1.3.34) with PostgreSQL: if a user isn't part of any teams, listUserTeams tries to run a query like id IN (), which causes a syntax error instead of returning an empty list. The root cause is that the backend doesn't handle empty arrays for the IN operator when building the SQL query. This is fixed in internal build 5311 and above, but not in 1.3.34. As a workaround, you can check for team memberships before calling listUserTeams, or filter on the client side if you can't upgrade yet. Upgrading to 5311+ will resolve the issue and return an empty array as expected. More details and related discussion are available [here](https://github.com/better-auth/better-auth/issues/5767). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/3967ba3e-19d5-491e-a5e9-434c7f966d86?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/3967ba3e-19d5-491e-a5e9-434c7f966d86?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/3967ba3e-19d5-491e-a5e9-434c7f966d86?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/3967ba3e-19d5-491e-a5e9-434c7f966d86?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3967ba3e-19d5-491e-a5e9-434c7f966d86?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/3967ba3e-19d5-491e-a5e9-434c7f966d86?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3967ba3e-19d5-491e-a5e9-434c7f966d86?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6054)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2325