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 the rest of the source files into the image.
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
CMD npm i
|
|
||||||
|
|
||||||
# Expose the port that the application listens on.
|
# Expose the port that the application listens on.
|
||||||
EXPOSE ${APP_PORT}
|
EXPOSE ${APP_PORT}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ services:
|
|||||||
SESSION_SECRET: ${SESSION_SECRET}
|
SESSION_SECRET: ${SESSION_SECRET}
|
||||||
JWT_SECRET: ${JWT_SECRET}
|
JWT_SECRET: ${JWT_SECRET}
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- ${APP_PORT}:${APP_PORT}
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
|
|
||||||
|
|||||||
3
index.js
3
index.js
@@ -10,10 +10,8 @@ const { initializeSocket } = require('./backend/socket.js');
|
|||||||
|
|
||||||
const bcrypt = require('bcrypt');
|
const bcrypt = require('bcrypt');
|
||||||
const saltRounds = 10;
|
const saltRounds = 10;
|
||||||
const { Server } = require('socket.io');
|
|
||||||
const { createServer } = require('node:http');
|
const { createServer } = require('node:http');
|
||||||
const server = createServer(app);
|
const server = createServer(app);
|
||||||
const io = initializeSocket(server);
|
|
||||||
const jwt = require('jsonwebtoken');
|
const jwt = require('jsonwebtoken');
|
||||||
const jwtSecret = process.env.JWT_SECRET;
|
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);
|
const match = await bcrypt.compare(password, result.rows[0].password);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
res.send('Incorrect Username or Password!');
|
res.send('Incorrect Username or Password!');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const token = jwt.sign({ username }, jwtSecret, {
|
const token = jwt.sign({ username }, jwtSecret, {
|
||||||
expiresIn: '30d' // token expires in 30 days
|
expiresIn: '30d' // token expires in 30 days
|
||||||
|
|||||||
Reference in New Issue
Block a user