fix(api): fixed being able to override user (#98)
* fix(api): fixed being able to override user * Update index.ts
This commit is contained in:
parent
5c980c21e5
commit
9208dbe2f3
1 changed files with 15 additions and 5 deletions
|
@ -16,10 +16,20 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.body.username) await prisma.user.update({
|
if (req.body.username) {
|
||||||
where: { id: user.id },
|
const existing = await prisma.user.findFirst({
|
||||||
data: { username: req.body.username }
|
where: {
|
||||||
});
|
username: req.body.username
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (existing && user.username !== req.body.username) {
|
||||||
|
return res.forbid('Username is already taken');
|
||||||
|
}
|
||||||
|
await prisma.user.update({
|
||||||
|
where: { id: user.id },
|
||||||
|
data: { username: req.body.username }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (req.body.embedTitle) await prisma.user.update({
|
if (req.body.embedTitle) await prisma.user.update({
|
||||||
where: { id: user.id },
|
where: { id: user.id },
|
||||||
|
@ -82,4 +92,4 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withZipline(handler);
|
export default withZipline(handler);
|
||||||
|
|
Loading…
Add table
Reference in a new issue