Complete implementation of pre-game setup flow allowing players to create games and submit lineups before gameplay starts. Backend Changes: - Extended games.py with create game, lineup submission, and game start endpoints - Added teams.py roster endpoint with season filtering - Enhanced SBA API client with player data fetching and caching - Comprehensive validation for lineup submission (position conflicts, DH rules) Frontend Changes: - Redesigned create.vue with improved team selection and game options - Enhanced index.vue with active/pending game filtering and navigation - Added lineup/[id].vue for interactive lineup builder with drag-and-drop - Implemented auth.client.ts plugin for client-side auth initialization - Added comprehensive TypeScript types for API contracts - Updated middleware for better auth handling Key Features: - Game creation with home/away team selection - Full lineup builder with position assignment and batting order - DH rule validation (pitcher can be excluded from batting order) - Season-based roster filtering (Season 3) - Auto-start game when both lineups submitted - Real-time game list updates Workflow: 1. Create game → select teams → set options 2. Submit home lineup → validate positions/order 3. Submit away lineup → validate positions/order 4. Game auto-starts → navigates to game page 5. WebSocket connection → loads game state Ready for Phase F4 - connecting gameplay UI to complete the at-bat loop. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
/**
|
|
* Auth Middleware
|
|
*
|
|
* Protects routes that require authentication.
|
|
* Redirects to login if user is not authenticated.
|
|
*
|
|
* Note: Auth state is initialized by the auth.client.ts plugin before this middleware runs.
|
|
*/
|
|
|
|
import { useAuthStore } from '~/store/auth'
|
|
|
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
const authStore = useAuthStore()
|
|
|
|
console.log('[Auth Middleware]', {
|
|
path: to.path,
|
|
isAuthenticated: authStore.isAuthenticated,
|
|
isTokenValid: authStore.isTokenValid,
|
|
hasUser: !!authStore.currentUser,
|
|
})
|
|
|
|
// Allow access if authenticated and token is valid
|
|
if (authStore.isAuthenticated && authStore.isTokenValid) {
|
|
return
|
|
}
|
|
|
|
// If token expired but we have a refresh token, try refreshing
|
|
if (authStore.isAuthenticated && !authStore.isTokenValid && process.client) {
|
|
console.log('[Auth Middleware] Token expired, attempting refresh')
|
|
// Don't await - let it refresh in background and redirect for now
|
|
authStore.refreshAccessToken()
|
|
}
|
|
|
|
// Redirect to login with return URL
|
|
console.log('[Auth Middleware] Redirecting to login')
|
|
return navigateTo({
|
|
path: '/auth/login',
|
|
query: { redirect: to.fullPath },
|
|
})
|
|
})
|