adds a fallback email to allow fallback gravatar (#2339)

pull/2345/head
Syed Ali Shahbaz 2022-04-01 15:37:58 +05:30 committed by GitHub
parent f71c0ddfc3
commit b33a3d5652
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 3 deletions

View File

@ -8,7 +8,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// const username = req.url?.substring(1, req.url.lastIndexOf("/")); // const username = req.url?.substring(1, req.url.lastIndexOf("/"));
const username = req.query.username as string; const username = req.query.username as string;
const user = await prisma.user.findUnique({ const user = await prisma.user.findUnique({
rejectOnNotFound: true,
where: { where: {
username: username, username: username,
}, },
@ -20,9 +19,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const emailMd5 = crypto const emailMd5 = crypto
.createHash("md5") .createHash("md5")
.update(user.email as string) .update((user?.email as string) || "guest@example.com")
.digest("hex"); .digest("hex");
const img = user.avatar; const img = user?.avatar;
if (!img) { if (!img) {
res.writeHead(302, { res.writeHead(302, {
Location: defaultAvatarSrc({ md5: emailMd5 }), Location: defaultAvatarSrc({ md5: emailMd5 }),