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
16
server/api/exists/email.get.ts
Normal file
16
server/api/exists/email.get.ts
Normal file
@ -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 };
|
||||
}
|
||||
});
|
16
server/api/exists/username.get.ts
Normal file
16
server/api/exists/username.get.ts
Normal file
@ -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 };
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user