useTeamContext composable. This system eliminates duplicate code across pages and provides consistent team switching, role checking, and permission management.
📖 For event bus fundamentals, see Global Event Bus
Overview
The team context composable solves common team management challenges:- Eliminates Code Duplication: Single source of truth for team state across all pages
- Automatic Team Switching: Responds to sidebar team selection events automatically
- Role-Based Access Control: Built-in computed properties for permissions (admin, owner)
- Type Safety: Full TypeScript support with proper Team types
- Persistent State: Integrates with event bus storage for cross-session persistence
- Reactive Updates: All properties are reactive and update automatically
When to Use
UseuseTeamContext in any page or component that needs:
- Access to the currently selected team
- Team switching functionality via sidebar
- Role-based permissions (admin, owner checks)
- Team ID for API calls
- Team-scoped data filtering
- Dashboard (
/views/dashboard/index.vue) - MCP Server List (
/views/mcp-server/index.vue) - Deployments List (
/views/deploy/index.vue) - Deployment Wizard (
/views/deploy/create.vue)
Architecture
Composable Location
💡 Tip: Read the source file for implementation details and inline documentation.
Integration Points
The composable integrates with several systems:- Event Bus: Listens for
team-selectedevents from sidebar - Storage: Persists
selected_team_idacross sessions - Team Service: Fetches team data with roles via API
- Vue Lifecycle: Automatic cleanup of event listeners
API Reference
Return Properties
Options
resourceCheck callback enables resource-specific access control (see Advanced Usage).
Usage
Basic Usage
Most pages only need basic team context:Permission Checks
Use computed properties for role-based access control:Team Switching
The composable automatically handles team switching from the sidebar. You just need to react to changes:Loading States
Handle loading and error states gracefully:Advanced Usage
Resource Access Control
For pages that display team-scoped resources (like installation detail pages), use theresourceCheck option:
Accessing Full Team Object
When you need more than just the ID:Migration Guide
Before: Manual Team Management
After: Using Composable
- ~70 lines of duplicate code eliminated per page
- Automatic event handling and cleanup
- Consistent behavior across all pages
- Built-in loading and error states
- Type-safe access to team properties
Best Practices
1. Destructure Only What You Need
2. Use Computed Properties for Permissions
3. Check for Team Before API Calls
4. Watch for Team Changes
Common Patterns
Dashboard/List Pages
Pages that show team-scoped lists:Resource Detail Pages
Pages that show specific resources:Forms/Wizards
Pages that create team-scoped resources:Troubleshooting
Team Not Loading
IfselectedTeam remains null:
- Check browser console for API errors
- Verify user has at least one team:
GET /api/users/me/teams - Check localStorage for
deploystack_selected_team_id - Ensure event bus is properly initialized in
main.ts
Team Switching Not Working
If sidebar team selection doesn’t update the composable:- Verify sidebar emits
team-selectedevent - Check event bus event listener registration
- Confirm
team-selectedevent includes correct payload:{ teamId, teamName } - Check browser console for errors in
handleTeamSelectedfunction
Permission Checks Failing
IfisAdmin or isOwner are incorrect:
- Verify API returns team with
roleandis_ownerfields - Check
GET /api/users/me/teamsresponse structure - Ensure Team type includes role properties
- Verify TeamService correctly maps API response
Related Documentation
- Global Event Bus - Event system integration
- Storage System - Persistent state management
- Team Management - Team concepts and features
Source Code
Composable Location:- Implementation details
- Type definitions
- Inline documentation
- Edge case handling

