-
thx. |
Beta Was this translation helpful? Give feedback.
Answered by
daffl
Nov 27, 2022
Replies: 1 comment 1 reply
-
I don't think the queries you are making will do what you expect. If you want to differentiate the error message between if email and username already exists, this should work: const { NotFound, GeneralError, BadRequest } = require("@feathersjs/errors");
module.exports = (options = {}) => {
return async (context) => {
const { app, data } = context;
const { total: emailTotal } = app.service("users").find({
query: {
email: data.email,
$limit: 0
},
});
const { total: usernameTotal } = app.service("users").find({
query: {
username: data.username,
$limit: 0
},
});
if (emailTotal > 0) {
throw new BadRequest(`Email already exists`)
}
if (usernameTotal > 0) {
throw new BadRequest(`Username already exists`)
}
};
}; |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
andysay
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think the queries you are making will do what you expect. If you want to differentiate the error message between if email and username already exists, this should work: