@@ -6,8 +6,6 @@ const crypto = require('crypto');
66const { redis} = require ( '@urbackend/common' ) ;
77const { Project} = require ( '@urbackend/common' ) ;
88const { authEmailQueue } = require ( '@urbackend/common' ) ;
9- const { checkLockout, recordFailedAttempt, clearLockout } = require ( '@urbackend/common' ) ;
10- const { AppError } = require ( '@urbackend/common' ) ;
119const { getRefreshSession, persistRefreshSession, revokeSessionChain } = require ( '@urbackend/common' ) ;
1210const { loginSchema, userSignupSchema, resetPasswordSchema, onlyEmailSchema, verifyOtpSchema, changePasswordSchema, sanitize } = require ( '@urbackend/common' ) ;
1311const { getConnection } = require ( '@urbackend/common' ) ;
@@ -1006,13 +1004,6 @@ module.exports.signup = async (req, res) => {
10061004 // Model.create handles validation and default values
10071005 const result = await Model . create ( newUserPayload ) ;
10081006
1009- try {
1010- // Fail-open: if Redis is unavailable, do not block successful signup.
1011- await clearLockout ( String ( project . _id ) , normalizedEmail ) ;
1012- } catch ( lockErr ) {
1013- console . error ( '[login-lockout] clearLockout failed after signup:' , lockErr ?. message || lockErr ) ;
1014- }
1015-
10161007 await redis . set ( `project:${ project . _id } :otp:verification:${ normalizedEmail } ` , otp , 'EX' , 300 ) ;
10171008 await setPublicOtpCooldown ( project . _id , normalizedEmail , 'verification' ) ;
10181009
@@ -1055,31 +1046,11 @@ module.exports.signup = async (req, res) => {
10551046 * Issues access and refresh tokens upon successful authentication.
10561047 * @route POST /api/userAuth/login
10571048 */
1058- module . exports . login = async ( req , res , next ) => {
1059- const sendAuthError = ( statusCode , message ) => {
1060- if ( typeof next === 'function' ) {
1061- return next ( new AppError ( statusCode , message ) ) ;
1062- }
1063- return res . status ( statusCode ) . json ( { error : message } ) ;
1064- } ;
1065-
1049+ module . exports . login = async ( req , res ) => {
10661050 try {
10671051 const project = req . project ;
10681052 const { email, password } = loginSchema . parse ( req . body ) ;
10691053 const normalizedEmail = email . toLowerCase ( ) . trim ( ) ;
1070- const projectId = String ( project . _id ) ;
1071-
1072- let lockStatus = { locked : false , retryAfterSeconds : 0 } ;
1073- try {
1074- // Fail-open: if Redis is unavailable, do not block login attempts.
1075- lockStatus = await checkLockout ( projectId , normalizedEmail ) ;
1076- } catch ( lockErr ) {
1077- console . error ( '[login-lockout] checkLockout failed:' , lockErr ?. message || lockErr ) ;
1078- }
1079-
1080- if ( lockStatus . locked ) {
1081- return sendAuthError ( 423 , `Account temporarily locked. Try again in ${ lockStatus . retryAfterSeconds } seconds.` ) ;
1082- }
10831054
10841055 const usersColConfig = project . collections . find ( c => c . name === 'users' ) ;
10851056 if ( ! usersColConfig ) return res . status ( 404 ) . json ( { error : "Auth collection not found" } ) ;
@@ -1089,43 +1060,10 @@ module.exports.login = async (req, res, next) => {
10891060
10901061 const user = await Model . findOne ( { email : normalizedEmail } ) . select ( '+password' ) ;
10911062
1092- if ( ! user ) {
1093- let failedStatus = { locked : false , retryAfterSeconds : 0 , attempts : 0 } ;
1094- try {
1095- // Fail-open: if Redis is unavailable, do not block login on attempt tracking.
1096- failedStatus = await recordFailedAttempt ( projectId , normalizedEmail ) ;
1097- } catch ( attemptErr ) {
1098- console . error ( '[login-lockout] recordFailedAttempt failed (user missing):' , attemptErr ?. message || attemptErr ) ;
1099- }
1100-
1101- if ( failedStatus . locked ) {
1102- return sendAuthError ( 423 , `Account temporarily locked. Try again in ${ failedStatus . retryAfterSeconds } seconds.` ) ;
1103- }
1104- return sendAuthError ( 400 , 'Invalid email or password' ) ;
1105- }
1063+ if ( ! user ) return res . status ( 400 ) . json ( { error : "Invalid email or password" } ) ;
11061064
11071065 const validPass = await bcrypt . compare ( password , user . password ) ;
1108- if ( ! validPass ) {
1109- let failedStatus = { locked : false , retryAfterSeconds : 0 , attempts : 0 } ;
1110- try {
1111- // Fail-open: if Redis is unavailable, do not block login on attempt tracking.
1112- failedStatus = await recordFailedAttempt ( projectId , normalizedEmail ) ;
1113- } catch ( attemptErr ) {
1114- console . error ( '[login-lockout] recordFailedAttempt failed (invalid password):' , attemptErr ?. message || attemptErr ) ;
1115- }
1116-
1117- if ( failedStatus . locked ) {
1118- return sendAuthError ( 423 , `Account temporarily locked. Try again in ${ failedStatus . retryAfterSeconds } seconds.` ) ;
1119- }
1120- return sendAuthError ( 400 , 'Invalid email or password' ) ;
1121- }
1122-
1123- try {
1124- // Fail-open: if Redis is unavailable, do not block successful login.
1125- await clearLockout ( projectId , normalizedEmail ) ;
1126- } catch ( clearErr ) {
1127- console . error ( '[login-lockout] clearLockout failed:' , clearErr ?. message || clearErr ) ;
1128- }
1066+ if ( ! validPass ) return res . status ( 400 ) . json ( { error : "Invalid email or password" } ) ;
11291067
11301068 const issuedTokens = await issueAuthTokens ( {
11311069 project,
@@ -1420,7 +1358,6 @@ module.exports.resetPasswordUser = async (req, res) => {
14201358 try {
14211359 const project = req . project ;
14221360 const { email, otp, newPassword } = resetPasswordSchema . parse ( req . body ) ;
1423- const normalizedEmail = email . toLowerCase ( ) . trim ( ) ;
14241361
14251362 const redisKey = `project:${ project . _id } :otp:reset:${ email } ` ;
14261363 const storedOtp = await redis . get ( redisKey ) ;
@@ -1442,13 +1379,6 @@ module.exports.resetPasswordUser = async (req, res) => {
14421379
14431380 if ( result . matchedCount === 0 ) return res . status ( 404 ) . json ( { error : "User not found" } ) ;
14441381
1445- try {
1446- // Fail-open: if Redis is unavailable, do not block password recovery success.
1447- await clearLockout ( String ( project . _id ) , normalizedEmail ) ;
1448- } catch ( lockErr ) {
1449- console . error ( '[login-lockout] clearLockout failed after password reset:' , lockErr ?. message || lockErr ) ;
1450- }
1451-
14521382 await redis . del ( redisKey ) ;
14531383 res . json ( { message : "Password updated successfully" } ) ;
14541384
0 commit comments