fixed crash on wrong login password for existing user, update docker-compose.yaml
This commit is contained in:
@@ -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}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ services:
|
||||
SESSION_SECRET: ${SESSION_SECRET}
|
||||
JWT_SECRET: ${JWT_SECRET}
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- ${APP_PORT}:${APP_PORT}
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
|
||||
3
index.js
3
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
|
||||
|
||||
Reference in New Issue
Block a user