feat(api): add user info GET endpoint and blocklist usernames
This commit is contained in:
parent
a6b2eae785
commit
cc1120355a
5 changed files with 110 additions and 4 deletions
|
@ -6,6 +6,7 @@ import {
|
|||
userFirstNameSchema,
|
||||
userNameSchema,
|
||||
userLastNameSchema,
|
||||
disallowedUsernames,
|
||||
} from '@/lib/validation/user';
|
||||
|
||||
/**
|
||||
|
@ -155,6 +156,16 @@ export const PUT = auth(async function PUT(req) {
|
|||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
// Check if the name already exists for another user
|
||||
const existingUser = await prisma.user.findUnique({
|
||||
where: { name },
|
||||
});
|
||||
if ((existingUser && existingUser.id !== req.auth.user.id) || disallowedUsernames.includes(name.toLowerCase())) {
|
||||
return NextResponse.json(
|
||||
{ message: 'Username in use by another account' },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
updateData.name = name;
|
||||
}
|
||||
if (first_name) {
|
||||
|
@ -185,6 +196,16 @@ export const PUT = auth(async function PUT(req) {
|
|||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
// Check if the email already exists for another user
|
||||
const existingUser = await prisma.user.findUnique({
|
||||
where: { email },
|
||||
});
|
||||
if (existingUser && existingUser.id !== req.auth.user.id) {
|
||||
return NextResponse.json(
|
||||
{ message: 'Email in use by another account' },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
updateData.email = email;
|
||||
}
|
||||
if (image) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue