From 741433ea04b023312a00f0d93d603d99889c9fcc Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 31 Dec 2023 13:37:38 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[fix]=20=EB=94=94=EB=B2=84=EA=B9=85?= =?UTF-8?q?=EC=9A=A9=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/user.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/models/user.js b/src/models/user.js index 3b56eec..2f95529 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -59,9 +59,6 @@ module.exports = { 'SELECT user_id, fcm_token FROM users WHERE fcm_token = ?'; const [selectFcmToken] = await db.query(sqlSelectByFcmToken, [fcmToken]); - console.log(selectFcmToken); - console.log(selectFcmToken.length >= 1); - if (selectFcmToken.length >= 1) { const sqlUpdate = 'UPDATE users SET fcm_token = null WHERE user_id = ?'; const [updateRows] = await db.queryWithTransaction(sqlUpdate, [ @@ -100,7 +97,7 @@ module.exports = { const [rows] = await db.query(sqlSelect, [email]); - if (rows.affectedRows < 1) { + if (rows.length > 1) { throw new NotFound(ErrorMessage.unValidateUser); } @@ -122,7 +119,7 @@ module.exports = { const [rows] = await db.query(sqlSelect, [userId]); - if (rows.affectedRows < 1) { + if (rows.length > 1) { throw new NotFound(ErrorMessage.unValidateUser); } From 26afca892c95348eef27641418a7ebb471b69f6a Mon Sep 17 00:00:00 2001 From: hyejungg Date: Sun, 31 Dec 2023 13:46:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20=EB=8F=99=EC=9D=BC=20=EA=B8=B0?= =?UTF-8?q?=EA=B8=B0=20=EB=8B=A4=EB=A5=B8=20=EC=9C=A0=EC=A0=80=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=98=88=EC=99=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/user.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/models/user.js b/src/models/user.js index 2f95529..ec80d5b 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -17,7 +17,7 @@ module.exports = { 'SELECT user_id, fcm_token FROM users WHERE fcm_token = ?'; const [selectRows] = await db.query(sqlSelect, [fcmToken]); - if (selectRows.length > 1) { + if (selectRows.length >= 1) { const sqlUpdate = 'UPDATE users SET fcm_token = null WHERE user_id = ?'; const [updateRows] = await db.queryWithTransaction(sqlUpdate, [ selectRows[0].user_id, @@ -54,12 +54,15 @@ module.exports = { const checkPassword = bcrypt.compareSync(password, selectRows[0].password); - // fcm 토큰이 다른 유저에 존재한다면, null 처리 + // fcm 토큰이 다른 유저에 존재한다면, 다른 유저를 null 처리 const sqlSelectByFcmToken = 'SELECT user_id, fcm_token FROM users WHERE fcm_token = ?'; const [selectFcmToken] = await db.query(sqlSelectByFcmToken, [fcmToken]); - if (selectFcmToken.length >= 1) { + if ( + selectFcmToken.length >= 1 && + selectFcmToken.user_id !== selectRows.user_id + ) { const sqlUpdate = 'UPDATE users SET fcm_token = null WHERE user_id = ?'; const [updateRows] = await db.queryWithTransaction(sqlUpdate, [ selectFcmToken[0].user_id, @@ -119,7 +122,7 @@ module.exports = { const [rows] = await db.query(sqlSelect, [userId]); - if (rows.length > 1) { + if (rows.length < 1) { throw new NotFound(ErrorMessage.unValidateUser); }