From 1c927f75f5fdedceddae7f8ff92e955aeb74548b Mon Sep 17 00:00:00 2001 From: slawk0 Date: Thu, 29 Aug 2024 19:13:40 +0200 Subject: [PATCH] fixed crash on wrong login password for existing user, update docker-compose.yaml --- Dockerfile | 2 -- docker-compose.yaml | 2 +- index.js | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2d557b6..c11a711 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,8 +31,6 @@ USER node # Copy the rest of the source files into the image. COPY . . -CMD npm i - # Expose the port that the application listens on. EXPOSE ${APP_PORT} diff --git a/docker-compose.yaml b/docker-compose.yaml index f2b01e6..8e6c080 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -13,7 +13,7 @@ services: SESSION_SECRET: ${SESSION_SECRET} JWT_SECRET: ${JWT_SECRET} ports: - - "3000:3000" + - ${APP_PORT}:${APP_PORT} depends_on: - db diff --git a/index.js b/index.js index c48d8f1..730d8c3 100644 --- a/index.js +++ b/index.js @@ -10,10 +10,8 @@ const { initializeSocket } = require('./backend/socket.js'); const bcrypt = require('bcrypt'); const saltRounds = 10; -const { Server } = require('socket.io'); const { createServer } = require('node:http'); const server = createServer(app); -const io = initializeSocket(server); const jwt = require('jsonwebtoken'); const jwtSecret = process.env.JWT_SECRET; @@ -163,6 +161,7 @@ async function loginUser(req, res) { const match = await bcrypt.compare(password, result.rows[0].password); if (!match) { res.send('Incorrect Username or Password!'); + return; } const token = jwt.sign({ username }, jwtSecret, { expiresIn: '30d' // token expires in 30 days