All files / composables useAuth.ts

100% Statements 32/32
100% Branches 8/8
100% Functions 5/5
100% Lines 32/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67            1x     1x 54x     54x     54x 54x 54x         54x 13x 13x         54x 5x 5x         54x 6x 6x         54x 2x 2x   54x   54x 54x 54x     54x 54x 54x     54x 54x 54x 54x 54x 54x  
/**
 * Auth Composable
 * Exposes auth store state and actions with proper reactivity
 * Provides mock authentication for demo purposes
 */
 
import { useAuthStore } from '~/stores/auth'
import type { User, Team } from '~/types'
 
export function useAuth() {
  const store = useAuthStore()
 
  // Extract reactive state and getters with storeToRefs
  const { user, team, isAuthenticated } = storeToRefs(store)
 
  // Computed getters
  const displayName = computed(() => store.displayName)
  const teamName = computed(() => store.teamName)
  const hasTeam = computed(() => store.hasTeam)
 
  /**
   * Login with optional custom user/team data
   */
  const login = (userData?: User, teamData?: Team): void => {
    store.login(userData, teamData)
  }
 
  /**
   * Logout and clear session
   */
  const logout = (): void => {
    store.logout()
  }
 
  /**
   * Toggle auth state (for demo purposes)
   */
  const toggleAuth = (): void => {
    store.toggleAuth()
  }
 
  /**
   * Update current team
   */
  const setTeam = (teamData: Team): void => {
    store.setTeam(teamData)
  }
 
  return {
    // Reactive state
    user,
    team,
    isAuthenticated,
 
    // Computed getters
    displayName,
    teamName,
    hasTeam,
 
    // Actions
    login,
    logout,
    toggleAuth,
    setTeam
  }
}