X Enterprises
nuxt-x-auth-better

Organizations & Teams

Better Auth Organizations & Teams support in nuxt-x-auth-better — components, pages, middleware, and server setup.

Organizations & Teams

The nuxt-x-auth-better layer includes a full Better Auth Organizations & Teams frontend implementation. Enable it in app.config.ts and add the Better Auth organization plugin on your server to get org/team switchers, member management, invitations, and role-based route protection out of the box.

Enabling

Set the feature flags in app.config.ts:

export default defineAppConfig({
  xAuth: {
    features: {
      organization: true,
      teams: true,
    },
    organization: {
      enabled: true,
      teams: true,
      allowUserToCreateOrganization: true,
      requireMemberEmailVerification: true,
      defaultRole: 'member',
      protectedRoutes: ['/org'],
      redirects: {
        create: '/org/create',
        list: '/org',
        settings: '/org/:slug/settings',
        invitations: '/org/:slug/invitations',
        notMember: '/org',
        noPermission: '/org',
      },
    },
  },
})

Teams are enabled by default when organizations are on, but can be disabled by setting organization.teams: false.

UI Components

Components are auto-imported with the XAuth prefix.

ComponentPurpose
XAuthOrganizationSwitcherList and navigate between organizations
XAuthOrganizationCreateCreate a new organization
XAuthOrganizationSettingsEdit or delete an organization
XAuthOrganizationMembersManage members and roles
XAuthOrganizationInviteInvite a new member
XAuthOrganizationInvitationsList pending invitations
XAuthTeamListList teams in an organization
XAuthTeamCreateCreate a team
XAuthTeamSettingsEdit or delete a team
XAuthTeamMembersManage team members

Auto-registered Pages

The layer provides these pages out of the box:

RoutePurpose
/orgOrganization list / switcher
/org/createCreate a new organization
/org/:slugOrganization dashboard
/org/:slug/settingsOrganization settings
/org/:slug/membersMember list
/org/:slug/inviteInvite member
/org/:slug/invitationsPending invitations
/org/:slug/teamsTeam list
/org/:slug/teams/createCreate team
/org/:slug/teams/:teamIdTeam settings + members
/auth/handler/invitation?id=...Public invitation accept handler

Middleware Behavior

organization.global.ts runs after auth.global.ts (Nuxt runs global middleware alphabetically by filename). It protects routes under /org by:

  1. Checking if organizations are enabled.
  2. Ensuring the user is authenticated; otherwise redirecting to redirects.login.
  3. Resolving the requested organization by slug and setting it active.
  4. Verifying the user is a member of the organization; otherwise redirecting to redirects.notMember.
  5. Enforcing any requireOwner, requireAdmin, requireMember, or requiredPermissions rules configured in organization.protectedRoutes.

Server-side Setup

Add the organization plugin to your BetterAuth server config. The layer's client plugin already registers organizationClient({ teams: { enabled: true } }), so server and client teams settings must agree.

// server/auth.ts
import { betterAuth } from 'better-auth'
import { organization } from 'better-auth/plugins'

export const auth = betterAuth({
  emailAndPassword: {
    enabled: true,
  },
  plugins: [
    organization({
      allowUserToCreateOrganization: true,
      teams: {
        enabled: true,
      },
    }),
  ],
})

For details on invitation email verification and custom access-control roles, see the INTEGRATION.md Organizations & Teams section.


AI Context

feature: Organizations & Teams
package: "@xenterprises/nuxt-x-auth-better"
use-when: >
  Building multi-tenant organization support with Better Auth in a Nuxt app
  using the nuxt-x-auth-better layer. Enables organization/team switchers,
  member management, invitations, and role-based route protection. Requires
  the Better Auth organization plugin on the server with teams.enabled when
  using teams. See composables/use-x-organization.md for the full API.
Copyright © 2026