diff --git a/server/api/exists/email.get.ts b/server/api/exists/email.get.ts new file mode 100644 index 0000000..e5b768f --- /dev/null +++ b/server/api/exists/email.get.ts @@ -0,0 +1,16 @@ +import { usernameRegex } from "~/lib/server/constants"; +import { User } from "~/models/user"; + +export default eventHandler(async (event) => { + const query = getQuery(event); + const u = await User.findOne({ + email: query.email as string, + }).exec(); + if (u) { + return { + exists: true, + }; + } else { + return { exists: false }; + } +}); diff --git a/server/api/exists/username.get.ts b/server/api/exists/username.get.ts new file mode 100644 index 0000000..c2d6d3b --- /dev/null +++ b/server/api/exists/username.get.ts @@ -0,0 +1,16 @@ +import { usernameRegex } from "~/lib/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 }; + } +});