[PR #6196] feat(organization): add optional slug field to teams #32115

Open
opened 2026-04-17 22:58:40 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6196
Author: @ImBIOS
Created: 11/22/2025
Status: 🔄 Open

Base: nextHead: feat/team-slug-support


📝 Commits (5)

  • 1af65cf feat(organization): add optional slug field to teams
  • fcd5026 refactor(organization): standardize formatting and improve readability in organization and team files
  • 17b1e72 feat(organization): add team slug error handling and clean up test instances
  • 618dd1c fix(organization): improve formatting of team slug error message
  • 3c7acc9 test(organization): add optional slug field to team type tests

📊 Changes

7 files changed (+371 additions, -3 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/adapter.ts (+21 -0)
📝 packages/better-auth/src/plugins/organization/error-codes.ts (+2 -0)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+2 -0)
📝 packages/better-auth/src/plugins/organization/organization.ts (+24 -0)
📝 packages/better-auth/src/plugins/organization/routes/crud-team.ts (+105 -2)
📝 packages/better-auth/src/plugins/organization/schema.ts (+6 -0)
📝 packages/better-auth/src/plugins/organization/team.test.ts (+211 -1)

📄 Description

Description

This PR adds support for an optional slug field to Teams, providing feature parity with Organizations. Slugs enable clean, readable URLs like /team/engineering and are unique within each organization.

Changes

Schema & Types

  • Added optional slug field to Team schema (organization-scoped uniqueness)
  • Updated TypeScript type definitions
  • Made slug sortable for efficient queries

Adapter

  • Added findTeamBySlug(slug, organizationId?) method for slug lookups

API Endpoints

  • Create Team: Validates slug uniqueness before creation
  • Update Team: Prevents duplicate slug conflicts on updates
  • Check Team Slug: New /organization/check-team-slug endpoint for availability checking

Tests

  • Create team with slug
  • Prevent duplicate slugs within same organization
  • Allow same slug across different organizations
  • Check slug availability
  • Update team slug
  • Prevent duplicate slugs on update
  • Support teams without slugs (optional field)

Design Decisions

  1. Optional Field: Slug is optional to maintain backward compatibility
  2. Organization-Scoped: Uniqueness enforced per organization (different orgs can have same slug)
  3. Application-Level Validation: Uses adapter queries for flexibility across databases
  4. Consistent Pattern: Follows exact same implementation as organization slugs

API Usage

// Create team with slug
await client.organization.createTeam({
  name: "Engineering",
  slug: "engineering",
  organizationId: "org-123"
});

// Check if slug is available
await auth.api.checkTeamSlug({
  body: { slug: "design", organizationId: "org-123" }
});

// Update slug
await client.organization.updateTeam({
  teamId: "team-456",
  data: { slug: "eng-team" }
});

Testing

All tests pass (32/32):

✓ src/plugins/organization/team.test.ts (32 tests) 3485ms
✓ 0 linter errors

Breaking Changes

None - slug field is optional and backward compatible.

Checklist

  • Tests added/updated
  • All tests pass
  • No linter errors
  • Follows existing code patterns
  • TypeScript types updated
  • Backward compatible

Summary by cubic

Adds optional team slugs with org-scoped uniqueness and an availability check to enable clean team URLs.

  • New Features
    • Teams: Optional team.slug, unique per organization; adapter findTeamBySlug; slug validation on create/update; POST /organization/check-team-slug; backward compatible.
    • Tests: Create/update with slug, prevent duplicates, availability check, allow same slug across orgs, support teams without slugs.

Written for commit 3c7acc96b6. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6196 **Author:** [@ImBIOS](https://github.com/ImBIOS) **Created:** 11/22/2025 **Status:** 🔄 Open **Base:** `next` ← **Head:** `feat/team-slug-support` --- ### 📝 Commits (5) - [`1af65cf`](https://github.com/better-auth/better-auth/commit/1af65cf8338ea32560ada3cbc41d956a396b6654) feat(organization): add optional slug field to teams - [`fcd5026`](https://github.com/better-auth/better-auth/commit/fcd5026f23275a13ba41b65ddaf680ea7ad6d3df) refactor(organization): standardize formatting and improve readability in organization and team files - [`17b1e72`](https://github.com/better-auth/better-auth/commit/17b1e7231bf91323e3068683199fcfc0b8d6b62a) feat(organization): add team slug error handling and clean up test instances - [`618dd1c`](https://github.com/better-auth/better-auth/commit/618dd1c1bd681cfa81859eec63561a270fb5916d) fix(organization): improve formatting of team slug error message - [`3c7acc9`](https://github.com/better-auth/better-auth/commit/3c7acc96b63080e63643c58f764c2a848adc4932) test(organization): add optional slug field to team type tests ### 📊 Changes **7 files changed** (+371 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+21 -0) 📝 `packages/better-auth/src/plugins/organization/error-codes.ts` (+2 -0) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+2 -0) 📝 `packages/better-auth/src/plugins/organization/organization.ts` (+24 -0) 📝 `packages/better-auth/src/plugins/organization/routes/crud-team.ts` (+105 -2) 📝 `packages/better-auth/src/plugins/organization/schema.ts` (+6 -0) 📝 `packages/better-auth/src/plugins/organization/team.test.ts` (+211 -1) </details> ### 📄 Description ## Description This PR adds support for an optional `slug` field to Teams, providing feature parity with Organizations. Slugs enable clean, readable URLs like `/team/engineering` and are unique within each organization. ## Changes ### Schema & Types - Added optional `slug` field to Team schema (organization-scoped uniqueness) - Updated TypeScript type definitions - Made slug sortable for efficient queries ### Adapter - Added `findTeamBySlug(slug, organizationId?)` method for slug lookups ### API Endpoints - **Create Team**: Validates slug uniqueness before creation - **Update Team**: Prevents duplicate slug conflicts on updates - **Check Team Slug**: New `/organization/check-team-slug` endpoint for availability checking ### Tests - [x] Create team with slug - [x] Prevent duplicate slugs within same organization - [x] Allow same slug across different organizations - [x] Check slug availability - [x] Update team slug - [x] Prevent duplicate slugs on update - [x] Support teams without slugs (optional field) ## Design Decisions 1. **Optional Field**: Slug is optional to maintain backward compatibility 2. **Organization-Scoped**: Uniqueness enforced per organization (different orgs can have same slug) 3. **Application-Level Validation**: Uses adapter queries for flexibility across databases 4. **Consistent Pattern**: Follows exact same implementation as organization slugs ## API Usage ```typescript // Create team with slug await client.organization.createTeam({ name: "Engineering", slug: "engineering", organizationId: "org-123" }); // Check if slug is available await auth.api.checkTeamSlug({ body: { slug: "design", organizationId: "org-123" } }); // Update slug await client.organization.updateTeam({ teamId: "team-456", data: { slug: "eng-team" } }); ``` ## Testing All tests pass (32/32): ``` ✓ src/plugins/organization/team.test.ts (32 tests) 3485ms ✓ 0 linter errors ``` ## Related - Fix #1849 - https://github.com/better-auth/better-auth/pull/1867 ## Breaking Changes None - slug field is optional and backward compatible. ## Checklist - [x] Tests added/updated - [x] All tests pass - [x] No linter errors - [x] Follows existing code patterns - [x] TypeScript types updated - [x] Backward compatible <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds optional team slugs with org-scoped uniqueness and an availability check to enable clean team URLs. - **New Features** - Teams: Optional team.slug, unique per organization; adapter findTeamBySlug; slug validation on create/update; POST /organization/check-team-slug; backward compatible. - Tests: Create/update with slug, prevent duplicates, availability check, allow same slug across orgs, support teams without slugs. <sup>Written for commit 3c7acc96b63080e63643c58f764c2a848adc4932. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 22:58:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#32115