/**
 * Auth Plugin - Client Side Only
 *
 * Checks authentication state from server-side cookies before any navigation occurs.
 * This ensures the auth middleware has the correct state when checking authentication.
 */

import { useAuthStore } from '~/store/auth'

export default defineNuxtPlugin(async () => {
  const authStore = useAuthStore()

  // Check auth status from cookies (calls /api/auth/me)
  await authStore.checkAuth()

  console.log('[Auth Plugin] Checked auth state:', {
    isAuthenticated: authStore.isAuthenticated,
    hasUser: !!authStore.currentUser,
  })
})
