Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const http = require('http');
const cors = require('cors');
const app = express();
require('dotenv').config();
const RateLimit = require('express-rate-limit');
const rateLimit = require('express-rate-limit');
const csrf = require('lusca').csrf;

const limiter = new RateLimit({
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
});
Expand All @@ -23,6 +23,12 @@ const corsOptions = {
credentials: true,
};

const SESSION_SECRET = process.env.SESSION_SECRET;

if (!SESSION_SECRET) {
throw new Error('Missing SESSION_SECRET environment variable.');
}

const start = async () => {
// configuration of passport is async
// Before we can bind the routes - we need the passport
Expand All @@ -32,9 +38,10 @@ const start = async () => {
app.use(limiter);
app.use(
session({
secret: process.env.SESSION_SECRET,
secret: SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: { secure: true },
}),
);
app.use(csrf());
Expand Down
7 changes: 6 additions & 1 deletion src/service/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ router.post('/password', async (req, res) => {
throw new Error('current password did not match the given');
}
} catch (e) {
res.status(500).send(e).end();
res
.status(500)
.send({
message: 'An error occurred',
})
.end();
}
} else {
res.status(401).end();
Expand Down