Organizations & Teams
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.
| Component | Purpose |
|---|---|
XAuthOrganizationSwitcher | List and navigate between organizations |
XAuthOrganizationCreate | Create a new organization |
XAuthOrganizationSettings | Edit or delete an organization |
XAuthOrganizationMembers | Manage members and roles |
XAuthOrganizationInvite | Invite a new member |
XAuthOrganizationInvitations | List pending invitations |
XAuthTeamList | List teams in an organization |
XAuthTeamCreate | Create a team |
XAuthTeamSettings | Edit or delete a team |
XAuthTeamMembers | Manage team members |
Auto-registered Pages
The layer provides these pages out of the box:
| Route | Purpose |
|---|---|
/org | Organization list / switcher |
/org/create | Create a new organization |
/org/:slug | Organization dashboard |
/org/:slug/settings | Organization settings |
/org/:slug/members | Member list |
/org/:slug/invite | Invite member |
/org/:slug/invitations | Pending invitations |
/org/:slug/teams | Team list |
/org/:slug/teams/create | Create team |
/org/:slug/teams/:teamId | Team 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:
- Checking if organizations are enabled.
- Ensuring the user is authenticated; otherwise redirecting to
redirects.login. - Resolving the requested organization by slug and setting it active.
- Verifying the user is a member of the organization; otherwise redirecting to
redirects.notMember. - Enforcing any
requireOwner,requireAdmin,requireMember, orrequiredPermissionsrules configured inorganization.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.
