Skip to content

Commit

Permalink
Merge pull request #147 from holabayor/main
Browse files Browse the repository at this point in the history
confirm invite error handling
  • Loading branch information
holabayor authored Sep 24, 2023
2 parents 97194c7 + cc5c0ea commit 7928b98
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions controllers/organizationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,40 +92,25 @@ const confirmInviteCode = async (req, res, next) => {
where: { token: verificationCode },
});

if (invite) {
res.email = invite.email;
res.org_id = invite.org_id;
res.status(200).json({
success: true,
message: 'Token verified',
data: {
org_id: invite.org_id,
email: invite.email,
},
});
} else {
createCustomError('Invalid verification code', 400);
if (!invite) {
throw createCustomError('Invalid verification code', 400);
}

// // Verifing the verification code against the stored code in your database
// const user = await orgInvites.findOne({
// where: { email, token: verificationCode },
// });

// if (!user || user.token !== verificationCode) {
// return res.status(400).json({
// success: false,
// message: 'Invalid email or verification code.',
// data: null,
// });
// }

// // Mark the email as verified
// user.email = true;
// user.token = null; // Optional, clear the verification code from the database or not
// // There is supposed to be a field where we set the state to be true once token is validated

// await user.save();
// Delete the verification code from the database
await orgInvites.destroy({
where: { token: verificationCode },
});

res.email = invite.email;
res.org_id = invite.org_id;
res.status(200).json({
success: true,
message: 'Token verified',
data: {
org_id: invite.org_id,
email: invite.email,
},
});
} catch (error) {
next(error);
}
Expand Down

0 comments on commit 7928b98

Please sign in to comment.