All files / stores auth.ts

100% Statements 51/51
100% Branches 16/16
100% Functions 8/8
100% Lines 51/51

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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103                                  1x 1x 1x 1x 1x 1x         1x 1x 1x 1x 1x   1x 1x 53x 53x 53x 53x   1x       1x 3x 3x         1x 18x 18x         1x 3x 3x 1x   1x         1x 31x 31x 31x 31x         1x 15x 15x 15x 15x         1x 6x 2x 6x 4x 4x 6x         1x 2x 2x 1x 1x  
/**
 * Auth Store
 * Manages authentication state with mock functionality for demo purposes
 * Will be replaced with real auth (JWT/OAuth) when backend is integrated
 */
 
import type { User, Team } from '~/types'
 
interface AuthState {
  user: User | null
  team: Team | null
  isAuthenticated: boolean
}
 
/**
 * Mock user data for demo purposes
 */
const MOCK_USER: User = {
  id: '1',
  name: 'Max Mustermann',
  email: 'max@spielerplus.de',
  avatar: undefined
}
 
/**
 * Mock team data for demo purposes
 */
const MOCK_TEAM: Team = {
  id: '1',
  name: 'FC Demo Team',
  logo: undefined
}
 
export const useAuthStore = defineStore('auth', {
  state: (): AuthState => ({
    user: null,
    team: null,
    isAuthenticated: false
  }),
 
  getters: {
    /**
     * Get current user's display name
     */
    displayName: (state: AuthState): string => {
      return state.user?.name ?? 'Guest'
    },
 
    /**
     * Get current team name
     */
    teamName: (state: AuthState): string => {
      return state.team?.name ?? ''
    },
 
    /**
     * Check if user has a team
     */
    hasTeam: (state: AuthState): boolean => {
      return state.team !== null
    }
  },
 
  actions: {
    /**
     * Mock login - simulates authentication
     * In production, this would call the auth API
     */
    login(user?: User, team?: Team): void {
      this.user = user ?? MOCK_USER
      this.team = team ?? MOCK_TEAM
      this.isAuthenticated = true
    },
 
    /**
     * Mock logout - clears authentication state
     */
    logout(): void {
      this.user = null
      this.team = null
      this.isAuthenticated = false
    },
 
    /**
     * Toggle auth state - for demo/development purposes
     */
    toggleAuth(): void {
      if (this.isAuthenticated) {
        this.logout()
      } else {
        this.login()
      }
    },
 
    /**
     * Update current team
     */
    setTeam(team: Team): void {
      this.team = team
    }
  }
})