[GH-ISSUE #5678] organization team update (renaming) does not work #18953

Closed
opened 2026-04-15 17:41:52 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @rem-aster on GitHub (Oct 30, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5678

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

i use these composables in nuxt. Everything updates correctly except teams

const client = createAuthClient({
	plugins: [
		emailOTPClient(),
		organizationClient({
			requireEmailVerificationOnInvitation: true,
			teams: {
				enabled: true,
			},
		}),
		adminClient(),
		apiKeyClient(),
	],
})

type Session = typeof client.$Infer.Session
type Organization = typeof client.$Infer.Organization
type ActiveOrganization = typeof client.$Infer.ActiveOrganization
type Invitation = typeof client.$Infer.Invitation
type Team = typeof client.$Infer.Team

export function useOrganization(organizationId: string) {
	const key = `auth:organization:${organizationId}`
	const pending = useState(`${key}:pending`, () => true)
	const init = useState(`${key}:init`, () => false)
	const data = useState<ActiveOrganization | null>(key, () => null)
	async function refresh() {
		if (pending.value && init.value) {
			return
		}
		pending.value = true
		const { data: res } = await client.organization.getFullOrganization({
			query: {
				organizationId,
			},
			fetchOptions: {
				onError: (ctx) => {
					toast.error(ctx.error.message)
				},
				onSuccess: async (ctx) => {
					if (ctx.data) {
						await useOrganizationTeamList(organizationId).refresh()
						await useOrganizationInvitationList(organizationId).refresh()
					}
				},
			},
		})
		data.value = res
		pending.value = false
		init.value = true
	}
	async function initialize() {
		if (!init.value) {
			await refresh()
		}
	}
	return { data, refresh, pending, initialize }
}

export function useOrganizationTeamList(organizationId: string) {
	const key = `auth:organization:${organizationId}:team:list`
	const pending = useState(`${key}:pending`, () => true)
	const init = useState(`${key}:init`, () => false)
	const data = useState<Team[] | null>(key, () => null)
	async function refresh() {
		if (pending.value && init.value) {
			return
		}
		pending.value = true
		const { data: res } = await client.organization.listTeams({
			query: {
				organizationId,
			},
			fetchOptions: {
				onError: (ctx) => {
					toast.error(ctx.error.message)
				},
			},
		})
		data.value = res
		pending.value = false
		init.value = true
	}
	async function initialize() {
		if (!init.value) {
			await refresh()
		}
	}
	return { data, refresh, pending, initialize }
}

export async function renameTeam(organizationId: string, teamId: string, name: string) {
	const { csrf } = useCsrf()
	const headers = new Headers()
	headers.append('csrf-token', csrf)
	await client.organization.updateTeam({ teamId, data: { name } }, {
		onError: (ctx) => {
			toast.error(ctx.error.message)
		},
		onSuccess: async (ctx) => {
			await useOrganization(organizationId).refresh()
			await useOrganizationTeamList(organizationId).refresh()
			// eslint-disable-next-line no-console
			console.log(ctx, organizationId, teamId, name) // I see OK status here
		},
		headers,
	})
}

Current vs. Expected behavior

Current: Ok status, data: null, no changes in team name ever after page reload (refetch)
Expected: Team renamed

What version of Better Auth are you using?

1.3.34

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Thu, 23 Oct 2025 18:49:03 +0000",
    "release": "6.17.5-arch1-1",
    "cpuCount": 12,
    "cpuModel": "13th Gen Intel(R) Core(TM) i5-13420H",
    "totalMemory": "15.34 GB",
    "freeMemory": "8.58 GB"
  },
  "node": {
    "version": "v22.19.0",
    "env": "development"
  },
  "packageManager": {
    "name": "pnpm",
    "version": "10.17.1"
  },
  "frameworks": [
    {
      "name": "vue",
      "version": "^3.5.22"
    },
    {
      "name": "nuxt",
      "version": "^4.2.0"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "drizzle",
      "version": "^0.44.7"
    }
  ],
  "betterAuth": {
    "version": "^1.3.34",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

default org with teams enabled

Additional context

No response

Originally created by @rem-aster on GitHub (Oct 30, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5678 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce i use these composables in nuxt. Everything updates correctly except teams ``` const client = createAuthClient({ plugins: [ emailOTPClient(), organizationClient({ requireEmailVerificationOnInvitation: true, teams: { enabled: true, }, }), adminClient(), apiKeyClient(), ], }) type Session = typeof client.$Infer.Session type Organization = typeof client.$Infer.Organization type ActiveOrganization = typeof client.$Infer.ActiveOrganization type Invitation = typeof client.$Infer.Invitation type Team = typeof client.$Infer.Team export function useOrganization(organizationId: string) { const key = `auth:organization:${organizationId}` const pending = useState(`${key}:pending`, () => true) const init = useState(`${key}:init`, () => false) const data = useState<ActiveOrganization | null>(key, () => null) async function refresh() { if (pending.value && init.value) { return } pending.value = true const { data: res } = await client.organization.getFullOrganization({ query: { organizationId, }, fetchOptions: { onError: (ctx) => { toast.error(ctx.error.message) }, onSuccess: async (ctx) => { if (ctx.data) { await useOrganizationTeamList(organizationId).refresh() await useOrganizationInvitationList(organizationId).refresh() } }, }, }) data.value = res pending.value = false init.value = true } async function initialize() { if (!init.value) { await refresh() } } return { data, refresh, pending, initialize } } export function useOrganizationTeamList(organizationId: string) { const key = `auth:organization:${organizationId}:team:list` const pending = useState(`${key}:pending`, () => true) const init = useState(`${key}:init`, () => false) const data = useState<Team[] | null>(key, () => null) async function refresh() { if (pending.value && init.value) { return } pending.value = true const { data: res } = await client.organization.listTeams({ query: { organizationId, }, fetchOptions: { onError: (ctx) => { toast.error(ctx.error.message) }, }, }) data.value = res pending.value = false init.value = true } async function initialize() { if (!init.value) { await refresh() } } return { data, refresh, pending, initialize } } export async function renameTeam(organizationId: string, teamId: string, name: string) { const { csrf } = useCsrf() const headers = new Headers() headers.append('csrf-token', csrf) await client.organization.updateTeam({ teamId, data: { name } }, { onError: (ctx) => { toast.error(ctx.error.message) }, onSuccess: async (ctx) => { await useOrganization(organizationId).refresh() await useOrganizationTeamList(organizationId).refresh() // eslint-disable-next-line no-console console.log(ctx, organizationId, teamId, name) // I see OK status here }, headers, }) } ``` ### Current vs. Expected behavior Current: Ok status, data: null, no changes in team name ever after page reload (refetch) Expected: Team renamed ### What version of Better Auth are you using? 1.3.34 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Thu, 23 Oct 2025 18:49:03 +0000", "release": "6.17.5-arch1-1", "cpuCount": 12, "cpuModel": "13th Gen Intel(R) Core(TM) i5-13420H", "totalMemory": "15.34 GB", "freeMemory": "8.58 GB" }, "node": { "version": "v22.19.0", "env": "development" }, "packageManager": { "name": "pnpm", "version": "10.17.1" }, "frameworks": [ { "name": "vue", "version": "^3.5.22" }, { "name": "nuxt", "version": "^4.2.0" } ], "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "drizzle", "version": "^0.44.7" } ], "betterAuth": { "version": "^1.3.34", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript default org with teams enabled ``` ### Additional context _No response_
GiteaMirror added the lockedneeds: infobugorganization labels 2026-04-15 17:41:52 -05:00
Author
Owner

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

It sounds like the updateTeam endpoint isn’t fully committing changes even though you’re getting an OK response. Here are some next steps to troubleshoot:

• Confirm that the server-side organization plugin is correctly configured to enable team updates. Although you’re using the default config with teams enabled, double‑check that no custom session or database hook is intercepting the update logic.

• Verify that the request payload (the teamId and new name) is received correctly on the backend. You might add some logging in your updateTeam endpoint to ensure the update query is executed and that the new name is passed as expected.

• Check the database updates directly to see if the team’s name is actually being written. If the update query is returning null data even though it succeeds, there might be a schema mismatch or caching issue.

• Since the refresh of the organization and team list “works” for other data, try clearing or bypassing any local caching that might be holding an older version of the team data. Sometimes using a direct GET teams call right after the update (or even checking via a separate database query) can shed light on whether it’s a client‐side caching issue.

• Finally, if everything seems correct on your side (payload, configuration, database), it is possible there’s a bug in the team update endpoint itself. In that case, raising an issue with a reproducible example on the project's repository would be the next step.

These steps should help you pinpoint whether the problem lies on the client side (e.g., through local state caching) or on the server side (e.g., not properly saving the new team name) [1], [2].

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3468162557 --> @better-auth-agent[bot] commented on GitHub (Oct 30, 2025): It sounds like the updateTeam endpoint isn’t fully committing changes even though you’re getting an OK response. Here are some next steps to troubleshoot: • Confirm that the server-side organization plugin is correctly configured to enable team updates. Although you’re using the default config with teams enabled, double‑check that no custom session or database hook is intercepting the update logic. • Verify that the request payload (the teamId and new name) is received correctly on the backend. You might add some logging in your updateTeam endpoint to ensure the update query is executed and that the new name is passed as expected. • Check the database updates directly to see if the team’s name is actually being written. If the update query is returning null data even though it succeeds, there might be a schema mismatch or caching issue. • Since the refresh of the organization and team list “works” for other data, try clearing or bypassing any local caching that might be holding an older version of the team data. Sometimes using a direct GET teams call right after the update (or even checking via a separate database query) can shed light on whether it’s a client‐side caching issue. • Finally, if everything seems correct on your side (payload, configuration, database), it is possible there’s a bug in the team update endpoint itself. In that case, raising an issue with a reproducible example on the project's repository would be the next step. These steps should help you pinpoint whether the problem lies on the client side (e.g., through local state caching) or on the server side (e.g., not properly saving the new team name) [[1]](https://github.com/better-auth/better-auth/issues/3591), [[2]](https://github.com/better-auth/better-auth/issues/5093). <!-- 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 (Oct 30, 2025):

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

This is likely caused by a schema mismatch in Better Auth's PostgreSQL integration: in some versions, the teamMember.teamId column is generated as text instead of integer, which breaks referential integrity with team.id (which is integer/serial). This prevents updates like renaming from persisting, even though the API returns an OK status. The bug was fixed in PR #3311 (merged July 2025).

To resolve this, upgrade Better Auth to a version that includes this fix. If upgrading isn't possible, manually edit your schema so that teamMember.teamId is integer (not text) and matches team.id. After correcting the schema, run migrations and try renaming again.

If you still see issues after fixing the schema, let me know what database rows you see for the affected team and team members.

To reply, just mention @dosu.


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

<!-- gh-comment-id:3468196374 --> @dosubot[bot] commented on GitHub (Oct 30, 2025): <!-- Greeting --> Hi @rem-aster! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is likely caused by a schema mismatch in Better Auth's PostgreSQL integration: in some versions, the `teamMember.teamId` column is generated as `text` instead of `integer`, which breaks referential integrity with `team.id` (which is `integer/serial`). This prevents updates like renaming from persisting, even though the API returns an OK status. The bug was fixed in [PR #3311](https://github.com/better-auth/better-auth/issues/3800) (merged July 2025). To resolve this, upgrade Better Auth to a version that includes this fix. If upgrading isn't possible, manually edit your schema so that `teamMember.teamId` is `integer` (not `text`) and matches `team.id`. After correcting the schema, run migrations and try renaming again. If you still see issues after fixing the schema, let me know what database rows you see for the affected team and team members. <!-- 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/3bd301d9-182b-401f-a51d-c2867eece6f1?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/3bd301d9-182b-401f-a51d-c2867eece6f1?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/3bd301d9-182b-401f-a51d-c2867eece6f1?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/3bd301d9-182b-401f-a51d-c2867eece6f1?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3bd301d9-182b-401f-a51d-c2867eece6f1?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/3bd301d9-182b-401f-a51d-c2867eece6f1?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3bd301d9-182b-401f-a51d-c2867eece6f1?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/5678)
Author
Owner

@ping-maxwell commented on GitHub (Jan 9, 2026):

Hello @rem-aster can you provide your auth config as well as code to show how you're updating the team?

<!-- gh-comment-id:3726948058 --> @ping-maxwell commented on GitHub (Jan 9, 2026): Hello @rem-aster can you provide your auth config as well as code to show how you're updating the team?
Author
Owner

@ping-maxwell commented on GitHub (Mar 27, 2026):

closing as stale.

<!-- gh-comment-id:4142023776 --> @ping-maxwell commented on GitHub (Mar 27, 2026): closing as stale.
Author
Owner

@github-actions[bot] commented on GitHub (Apr 4, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4185771729 --> @github-actions[bot] commented on GitHub (Apr 4, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18953