34 lines
915 B
TypeScript
34 lines
915 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { prisma } from "@repo/db";
|
|
|
|
export async function GET(req: Request) {
|
|
const { searchParams } = new URL(req.url);
|
|
const publicId = searchParams.get("publicId")?.trim();
|
|
const email = searchParams.get("email")?.trim()?.toLowerCase();
|
|
|
|
if (!publicId && !email) {
|
|
return NextResponse.json({ error: "Missing query" }, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
const user = await prisma.user.findFirst({
|
|
where: {
|
|
OR: [publicId ? { publicId } : undefined, email ? { email } : undefined].filter(
|
|
Boolean,
|
|
) as any,
|
|
},
|
|
select: {
|
|
id: true,
|
|
publicId: true,
|
|
firstname: true,
|
|
lastname: true,
|
|
isBanned: true,
|
|
},
|
|
});
|
|
if (!user) return NextResponse.json({ user: null }, { status: 200 });
|
|
return NextResponse.json({ user }, { status: 200 });
|
|
} catch (e) {
|
|
return NextResponse.json({ error: "Server error" }, { status: 500 });
|
|
}
|
|
}
|