feat(api): create endpoints to check if a given username/email already exists in the database

This commit is contained in:
parent a0f028cbf1
commit a63a470a10
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
2 changed files with 32 additions and 0 deletions

@ -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 };
}
});

@ -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 };
}
});