Skip to content

Commit b68a61c

Browse files
authored
Merge pull request #67 from eldimious/feature/use-express-jwt
use express jwt
2 parents ac1b268 + 640352c commit b68a61c

File tree

5 files changed

+60
-37
lines changed

5 files changed

+60
-37
lines changed

package-lock.json

Lines changed: 48 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"cors": "^2.8.5",
3131
"dotenv": "^14.2.0",
3232
"express": "^4.17.2",
33+
"express-jwt": "^6.1.0",
3334
"express-validator": "^6.14.0",
3435
"express-winston": "^4.2.0",
3536
"helmet": "^5.0.1",

src/presentation/http/app.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ const logger = require('morgan');
77
const helmet = require('helmet');
88
const path = require('path');
99
const swaggerUi = require('swagger-ui-express');
10-
const asyncWrapper = require('@dimosbotsaris/express-async-handler');
1110
const { errorHandler } = require('@dimosbotsaris/express-error-handler');
12-
const authenticateEndpoint = require('./middleware/authentication');
11+
const jwt = require('express-jwt');
1312
const authRoutes = require('./routes/auth/routes');
1413
const usersRoutes = require('./routes/users/routes');
1514
const swaggerDocument = require('../../swagger');
15+
const {
16+
jwtSecret,
17+
} = require('../../configuration');
1618

1719
const app = express();
1820
app.disable('x-powered-by');
@@ -29,10 +31,14 @@ module.exports.init = (services) => {
2931
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, {
3032
explorer: true,
3133
}));
34+
app.use(jwt({
35+
secret: jwtSecret,
36+
algorithms: ['HS256'],
37+
})
38+
.unless({
39+
path: ['/auth/register', '/auth/login'],
40+
}));
3241
app.use('/auth', authRoutes.init(services));
33-
app.all('*', asyncWrapper(authenticateEndpoint(services)), (req, res, next) => {
34-
next();
35-
});
3642
app.use('/users', usersRoutes.init(services));
3743
app.use(errorHandler({ trace: true }));
3844
const httpServer = http.createServer(app);

src/presentation/http/middleware/authentication.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/presentation/http/utils/getRequestParams.js

Whitespace-only changes.

0 commit comments

Comments
 (0)