forked from NotNet/gluestick
add api route for querying user information
This commit is contained in:
parent
33e680a43f
commit
4ce2931348
|
@ -27,6 +27,7 @@ declare global {
|
|||
GITHUB_ORG: string;
|
||||
|
||||
BASE_DOMAIN: string;
|
||||
API_TOKEN?: string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
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
|
||||
})
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue