import { NextRequest, NextResponse } from 'next/server';
import { cookies } from 'next/headers';

export async function GET(req: NextRequest) {
  try {
    const cookieStore = await cookies();
    const token = cookieStore.get('token')?.value;
    const getUser = cookieStore.get('getUser')?.value;

    if (!token) {
      return NextResponse.json(
        { authenticated: false },
        { status: 200 }
      );
    }

    return NextResponse.json({
      authenticated: true,
      user: getUser ? JSON.parse(getUser) : null,
    });
  } catch (error) {
    console.error('Auth check failed');
    return NextResponse.json(
      { authenticated: false },
      { status: 200 }
    );
  }
}
