// components/AuthInitializer.js
'use client'
import { useEffect } from 'react'
import { useAuthStore } from '@/stores/authStore'

export default function AuthInitializer() {
    const { login } = useAuthStore()

    useEffect(() => {
        async function checkAuth() {
            try {
                const res = await fetch('/api/profiles/me', { credentials: 'include' })
                if (res.ok) {
                    const userData = await res.json()

                    login(userData.user, userData.token);
                }
            } catch (error) {
                console.error('Auth check failed:', error)
            }
        }
        checkAuth()
    }, [login])

    return null
}