42 lines
955 B
TypeScript
42 lines
955 B
TypeScript
import { NextRequest } from "next/server";
|
|
import prisma from "@/prisma";
|
|
import * as ldap from "@/ldap";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: { username: string } }
|
|
) {
|
|
const { username } = params;
|
|
|
|
if (
|
|
process.env.API_TOKEN == null ||
|
|
process.env.API_TOKEN !== request.headers.get("Authorization")
|
|
) {
|
|
return new Response(null, { status: 401 });
|
|
}
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: { username: username as string }
|
|
});
|
|
|
|
if (user == null) {
|
|
return new Response(null, { status: 404 });
|
|
}
|
|
|
|
const ldapUser = await ldap.getUserInfo(user);
|
|
if (ldapUser == null) {
|
|
return new Response(null, { status: 404 });
|
|
}
|
|
|
|
return new Response(
|
|
JSON.stringify({
|
|
...ldapUser,
|
|
avatar: ldapUser.avatar ?? null,
|
|
discordId: ldapUser.discordId ?? null,
|
|
githubId: ldapUser.githubId ?? null
|
|
})
|
|
);
|
|
}
|