export async function GET(req) {
    try {
        const res = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/profiles/me`, {
            credentials: "include",
            headers: {
                cookie: req.headers.get("cookie") || "",
            }
        });

        if (!res.ok) throw new Error("Invalid token");

        const data = await res.json();
        return new Response(JSON.stringify({ user: data }), { status: 200 });
    } catch (error) {
        return new Response(JSON.stringify({ error: "Unauthorized" }), { status: 401 });
    }
}
