Skip to content

Commit

Permalink
Docker-compose - use .env file for session and JWT secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelberston committed Nov 19, 2024
1 parent 07582f9 commit 1303b96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/routes/protectedRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function authenticateToken(req, res, next) {
}

jwt.verify(token, process.env.JWT_SECRET, (err, user) => {
if (!process.env.JWT_SECRET) {
logger.error('JWT_SECRET environment variable is not set');
return res.status(500).json({ message: 'Server configuration error' });
}
if (err) {
logger.warn(`Attempt to access protected data with expired JWT from IP: %s`, req.ip);
return res.status(403).json({ message: 'Token invalid or expired.' });
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
container_name: backend
ports:
- "3000:3000"
env_file:
- .env
environment:
- PORT=3000
- DB_HOST=host.docker.internal
Expand Down

0 comments on commit 1303b96

Please sign in to comment.