2026-01-20 09:02:26 -06:00

55 lines
1.4 KiB
TypeScript

import { getUser } from "../../../services/userService.ts";
import { define } from "../../../utils.ts";
import { SessionCookie } from "../../auth/callback.ts";
export const handler = define.handlers({
GET: async (ctx) => {
try {
// Get userId from URL parameters
const url = new URL(ctx.req.url);
const userId = url.searchParams.get("userId");
if (!userId) {
return new Response(
JSON.stringify({ error: "userId parameter is required" }),
{
status: 400,
headers: { "Content-Type": "application/json" },
},
);
}
// Retrieve user data
const userData = await getUser(userId);
if (!userData) {
return new Response(
JSON.stringify({ error: "User not found" }),
{
status: 404,
headers: { "Content-Type": "application/json" },
},
);
}
// Return user data
return new Response(
JSON.stringify(userData),
{
status: 200,
headers: { "Content-Type": "application/json" },
},
);
} catch (error) {
console.error("Error retrieving user:", error);
return new Response(
JSON.stringify({ error: "Internal server error" }),
{
status: 500,
headers: { "Content-Type": "application/json" },
},
);
}
},
});