Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit e9419ed

Browse files
ignore invites that are already in use
1 parent 4053bf2 commit e9419ed

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

server/services/users/hooks/invite-code.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
1818
}
1919
const inviteRes = await hook.app.service('invites').find(query);
2020
// throw an error if the invite code does not match the one from the invite
21-
if (!inviteRes.data.length) {
21+
if (inviteRes.data.length !== 1) {
2222
throw new errors.Forbidden('invite code is invalid');
2323
}
2424

25+
if (inviteRes.data[0].wasUsed) {
26+
throw new errors.Forbidden('invite already used');
27+
}
28+
2529
// set some user data from the invite like batches and roles
2630
hook.data.wasInvited = true;
2731
hook.data.inviteId = inviteRes.data[0]._id;

0 commit comments

Comments
 (0)