ADD: redis client and inject the login-attempt logic into loginUser function

This commit is contained in:
MohammadHMazarei
2024-12-24 19:29:59 +03:30
parent 8cfea998a5
commit 8fae7769fd
+4 -3
View File
@@ -1,6 +1,7 @@
// userService.js // userService.js
const User = require('./userModel') const User = require('./userModel')
const AppError = require('../../globalErrorHandler/AppError') const AppError = require('../../globalErrorHandler/AppError')
const redisClient = require('../../setup/redis')
const jwt = require('jsonwebtoken') const jwt = require('jsonwebtoken')
const bcrypt = require('bcryptjs') const bcrypt = require('bcryptjs')
const maxAge = 60 * 60 * 24 * 90 const maxAge = 60 * 60 * 24 * 90
@@ -85,9 +86,9 @@ const loginUser = async (email, password) => {
const user = await User.findOne({ email }, null, null).select('+password') const user = await User.findOne({ email }, null, null).select('+password')
// if (email) { if (email) {
// await loginAttempt(email) await loginAttempt(email)
// } }
if (!user || !(await bcrypt.compare(password, user.password))) { if (!user || !(await bcrypt.compare(password, user.password))) {
throw new AppError('IncorrectEmailOrPassword', 401, {}) throw new AppError('IncorrectEmailOrPassword', 401, {})