diff --git a/src/app/api/register/route.ts b/src/app/api/register/route.ts index 1bb5b01..ea49f13 100644 --- a/src/app/api/register/route.ts +++ b/src/app/api/register/route.ts @@ -74,7 +74,7 @@ export async function POST(request: Request) { ); } - let avatarBuf: Buffer | undefined; + let avatarBuf: Buffer | null | undefined; if (avatarBase64 !== null && typeof avatarBase64 === "string") { avatarBuf = Buffer.from(avatarBase64, "base64"); @@ -112,7 +112,7 @@ export async function POST(request: Request) { } } - await ldap.createUser(username, displayName, email, avatarBuf); + await ldap.createUser(username, displayName, email, avatarBuf ?? undefined); await ldap.setPassword(username, password); const outputUser = await prisma.user.update({ diff --git a/src/app/api/update/route.ts b/src/app/api/update/route.ts index 1d984b5..5fe0868 100644 --- a/src/app/api/update/route.ts +++ b/src/app/api/update/route.ts @@ -5,7 +5,7 @@ import { getLogger } from "@/logger"; type RequestBody = { displayName?: string; email?: string; - avatarBase64?: string; + avatar?: string; }; export async function POST(request: Request) { @@ -20,8 +20,11 @@ export async function POST(request: Request) { return new Response(null, { status: 409 }); } - const { displayName, email, avatarBase64 } = - (await request.json()) as RequestBody; + const { + displayName, + email, + avatar: avatarBase64 + } = (await request.json()) as RequestBody; let changeDisplayName = false; if ( @@ -77,7 +80,7 @@ export async function POST(request: Request) { username: user.username, displayName: changeDisplayName ? displayName : null, email: changeEmail ? email : null, - avatar: avatarBuf ? avatarBuf.toString("base64") : null + avatar: avatarBuf ? `${avatarBuf.length} bytes` : null }, "updated user" ); diff --git a/src/app/oauth/discord/oauth.ts b/src/app/oauth/discord/oauth.ts index d8e10e3..ea8ef3d 100644 --- a/src/app/oauth/discord/oauth.ts +++ b/src/app/oauth/discord/oauth.ts @@ -10,7 +10,7 @@ export type DiscordAccessTokenResponse = { export type DiscordUserResponse = { id: string; - avatar: string; + avatar: string | null; }; export type DiscordGuildResponse = { @@ -49,6 +49,7 @@ export async function getDiscordAvatar(token: string) { }); const res: DiscordUserResponse = await req.json(); + if (res.avatar === null) return null; const file = `https://cdn.discordapp.com/avatars/${res.id}/${res.avatar}.png`; const avatarReq = await fetch(file);