import type { APIRoute } from 'astro';
import { getUserFromRequest } from '../../../lib/user-auth';

export const GET: APIRoute = async ({ request }) => {
  const user = getUserFromRequest(request);
  if (!user) {
    return new Response(JSON.stringify({ user: null }), {
      headers: { 'Content-Type': 'application/json' },
    });
  }
  return new Response(JSON.stringify({ user: { id: user.id, email: user.email } }), {
    headers: { 'Content-Type': 'application/json' },
  });
};
