🪙 refactor: Auth Token Retrieval with Sorting and Query Options (#9884)

This commit is contained in:
Danny Avila 2025-09-29 09:06:40 -04:00 committed by GitHub
parent a1471c2f37
commit c0eb19730a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 201 additions and 8 deletions

View file

@ -129,7 +129,7 @@ const verifyEmail = async (req) => {
return { message: 'Email already verified', status: 'success' };
}
let emailVerificationData = await findToken({ email: decodedEmail });
let emailVerificationData = await findToken({ email: decodedEmail }, { sort: { createdAt: -1 } });
if (!emailVerificationData) {
logger.warn(`[verifyEmail] [No email verification data found] [Email: ${decodedEmail}]`);
@ -319,9 +319,12 @@ const requestPasswordReset = async (req) => {
* @returns
*/
const resetPassword = async (userId, token, password) => {
let passwordResetToken = await findToken({
userId,
});
let passwordResetToken = await findToken(
{
userId,
},
{ sort: { createdAt: -1 } },
);
if (!passwordResetToken) {
return new Error('Invalid or expired password reset token');