Skip to content

Commit

Permalink
[fix] 동일 기기 다른 유저 로그인 예외 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hyejungg committed Dec 31, 2023
1 parent 741433e commit 26afca8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 26afca8

Please sign in to comment.