X Enterprises
Composables

useOrganization

Better Auth Organizations & Teams composable for nuxt-x-auth-better — org management, members, invitations, teams, and access control.

useOrganization

Better Auth organizations and teams composable for the nuxt-x-auth-better layer. Wraps the Better Auth organizationClient with reactive state for the user's organizations, active organization, members, invitations, and teams. All organization and team UI components in this layer consume useOrganization internally.

Usage

const {
  isEnabled,
  teamsEnabled,
  config,

  organizations,
  organizationsLoading,
  organizationsError,

  activeOrganization,
  activeLoading,
  activeError,

  activeMember,
  activeMemberRole,
  members,
  invitations,
  teams,

  canCreateOrganization,
  isOrgAdmin,
  isOrgOwner,

  createOrganization,
  updateOrganization,
  deleteOrganization,
  setActiveOrganization,
  getFullOrganization,
  checkSlug,

  listMembers,
  updateMemberRole,
  removeMember,
  leaveOrganization,

  inviteMember,
  cancelInvitation,
  acceptInvitation,
  rejectInvitation,
  getInvitation,
  listInvitations,
  listUserInvitations,

  listTeams,
  createTeam,
  updateTeam,
  deleteTeam,
  setActiveTeam,
  listTeamMembers,
  addTeamMember,
  removeTeamMember,
  listUserTeams,

  hasPermission,
  checkRolePermission,
  getDefaultPermissions,

  authClient,
} = useOrganization()

Returns

Feature Flags

KeyTypeDescription
isEnabledComputedRef<boolean>true when features.organization is enabled in app.config.ts and organization.enabled is not false.
teamsEnabledComputedRef<boolean>true when organizations are enabled and organization.teams is not false.
configComputedRef<OrganizationConfig>Reactive reference to the xAuth.organization app config from app.config.ts.

State

KeyTypeDescription
organizationsComputedRef<Organization[]>All organizations the current user belongs to.
organizationsLoadingComputedRef<boolean>true while the organization list is being fetched.
organizationsErrorComputedRef<Error | null>Any error returned while fetching the organization list.
activeOrganizationComputedRef<Organization | null>The currently active organization.
activeLoadingComputedRef<boolean>true while the active organization is being resolved.
activeErrorComputedRef<Error | null>Any error returned while resolving the active organization.
activeMemberComputedRef<OrganizationMember | null>The current user's member record in the active organization.
activeMemberRoleComputedRef<string | null>The current user's role in the active organization.
membersComputedRef<OrganizationMember[]>Members of the active organization.
invitationsComputedRef<OrganizationInvitation[]>Pending invitations in the active organization.
teamsComputedRef<OrganizationTeam[]>Teams in the active organization.
canCreateOrganizationComputedRef<boolean>true unless organization.allowUserToCreateOrganization is false.
isOrgAdminComputedRef<boolean>true when the active member role is owner or admin.
isOrgOwnerComputedRef<boolean>true when the active member role is owner.

Organization Methods

KeyTypeDescription
createOrganization(name: string, slug?: string, logo?: string) => Promise<Organization | null | { error: string }>Creates a new organization and optionally sets a slug and logo.
updateOrganization(data: { organizationId?: string; name?: string; slug?: string; logo?: string }) => Promise<Organization | null | { error: string }>Updates an organization's name, slug, or logo.
deleteOrganization(organizationId?: string) => Promise<boolean | { error: string }>Deletes an organization.
setActiveOrganization(organizationId?: string | null, organizationSlug?: string) => Promise<Organization | null | { error: string }>Sets the active organization by ID or slug.
getFullOrganization(organizationId?: string, organizationSlug?: string) => Promise<Organization | null | { error: string }>Fetches the full organization record including members, invitations, and teams.
checkSlug(slug: string) => Promise<{ status: boolean } | null | { error: string }>Checks whether an organization slug is available.

Member Methods

KeyTypeDescription
listMembers(organizationId?: string) => Promise<OrganizationMember[] | null | { error: string }>Lists members of the active or specified organization.
updateMemberRole(memberId: string, role: string | string[], organizationId?: string) => Promise<OrganizationMember | null | { error: string }>Updates a member's role.
removeMember(memberId: string, organizationId?: string) => Promise<{ success: boolean } | { error: string }>Removes a member from the organization.
leaveOrganization() => Promise<{ success: boolean } | { error: string }>Removes the current user from the active organization.

Invitation Methods

KeyTypeDescription
inviteMember(email: string, role: string | string[], organizationId?: string) => Promise<OrganizationInvitation | null | { error: string }>Invites a user to the active or specified organization.
cancelInvitation(invitationId: string) => Promise<{ success: boolean } | { error: string }>Cancels a pending invitation.
acceptInvitation(invitationId: string) => Promise<{ success: boolean } | { error: string }>Accepts an organization invitation.
rejectInvitation(invitationId: string) => Promise<{ success: boolean } | { error: string }>Rejects an organization invitation.
getInvitation(invitationId: string) => Promise<OrganizationInvitation | null | { error: string }>Fetches a single invitation by ID.
listInvitations(organizationId?: string) => Promise<OrganizationInvitation[] | null | { error: string }>Lists pending invitations for the active or specified organization.
listUserInvitations() => Promise<OrganizationInvitation[] | null | { error: string }>Lists invitations sent to the current user.

Team Methods

KeyTypeDescription
listTeams(organizationId?: string) => Promise<OrganizationTeam[] | null | { error: string }>Lists teams in the active or specified organization.
createTeam(name: string, organizationId?: string) => Promise<OrganizationTeam | null | { error: string }>Creates a new team.
updateTeam(teamId: string, data: { name?: string }, organizationId?: string) => Promise<OrganizationTeam | null | { error: string }>Updates a team's name.
deleteTeam(teamId: string, organizationId?: string) => Promise<{ success: boolean } | { error: string }>Deletes a team.
setActiveTeam(teamId: string) => Promise<OrganizationTeam | null | { error: string }>Sets the active team within the active organization.
listTeamMembers(teamId: string) => Promise<OrganizationMember[] | null | { error: string }>Lists members of a team.
addTeamMember(teamId: string, memberId: string, organizationId?: string) => Promise<{ success: boolean } | { error: string }>Adds an organization member to a team.
removeTeamMember(teamId: string, memberId: string) => Promise<{ success: boolean } | { error: string }>Removes a member from a team.
listUserTeams() => Promise<OrganizationTeam[] | null | { error: string }>Lists teams the current user belongs to across organizations.

Access Control

KeyTypeDescription
hasPermission(permissionCheck: PermissionCheck) => booleanChecks whether the active member has the requested permissions.
checkRolePermission(role: string, permissions: Record<string, string[]>) => booleanChecks whether a given role satisfies the provided permission map.
getDefaultPermissions(role: string) => Record<string, string[]>Returns the layer's default permission map for owner, admin, or member.

Utilities

KeyTypeDescription
authClientBetterAuthClientThe underlying Better Auth client instance for direct SDK access.

Examples

<script setup>
const { organizations, activeOrganization, setActiveOrganization } = useOrganization()

async function switchOrg(slug) {
  await setActiveOrganization(null, slug)
}
</script>

<template>
  <div>
    <p>Active: {{ activeOrganization?.name }}</p>
    <USelect
      :model-value="activeOrganization?.slug"
      :items="organizations.map(o => ({ label: o.name, value: o.slug }))"
      @update:model-value="switchOrg"
    />
  </div>
</template>
// Invite a member
const { inviteMember } = useOrganization()
await inviteMember('new@example.com', 'member')

// Create a team (requires teams.enabled)
const { createTeam } = useOrganization()
await createTeam('Engineering')

AI Context

composable: useOrganization
package: "@xenterprises/nuxt-x-auth-better"
use-when: >
  Organization and team management in a Nuxt app using the nuxt-x-auth-better
  layer (Better Auth backend). Provides reactive state and methods for
  organizations, members, invitations, teams, and role-based access control.
  Requires the Better Auth organization plugin on the server with
  teams.enabled when using teams. Pairs with fastify-x-auth-better on the
  server side.
Copyright © 2026