next/server/api/exists/username.get.ts

17 lines
353 B
TypeScript
Raw Normal View History

import { usernameRegex } from "@server/constants";
import { User } from "@models/user";
export default eventHandler(async (event) => {
const query = getQuery(event);
const u = await User.findOne({
username: usernameRegex(query.username as string),
}).exec();
if (u) {
return {
exists: true,
};
} else {
return { exists: false };
}
});