Skip to main content
The DeployStack frontend provides a centralized team context management system through the 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

Use useTeamContext 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
Pages currently using this composable:
  • 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:
  1. Event Bus: Listens for team-selected events from sidebar
  2. Storage: Persists selected_team_id across sessions
  3. Team Service: Fetches team data with roles via API
  4. Vue Lifecycle: Automatic cleanup of event listeners

API Reference

Return Properties

Options

The optional 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 the resourceCheck option:

Accessing Full Team Object

When you need more than just the ID:

Migration Guide

Before: Manual Team Management

After: Using Composable

Benefits:
  • ~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

If selectedTeam remains null:
  1. Check browser console for API errors
  2. Verify user has at least one team: GET /api/users/me/teams
  3. Check localStorage for deploystack_selected_team_id
  4. Ensure event bus is properly initialized in main.ts

Team Switching Not Working

If sidebar team selection doesn’t update the composable:
  1. Verify sidebar emits team-selected event
  2. Check event bus event listener registration
  3. Confirm team-selected event includes correct payload: { teamId, teamName }
  4. Check browser console for errors in handleTeamSelected function

Permission Checks Failing

If isAdmin or isOwner are incorrect:
  1. Verify API returns team with role and is_owner fields
  2. Check GET /api/users/me/teams response structure
  3. Ensure Team type includes role properties
  4. Verify TeamService correctly maps API response

Source Code

Composable Location:
Read the source code for:
  • Implementation details
  • Type definitions
  • Inline documentation
  • Edge case handling
Usage Examples: