Skip to content

Commit

Permalink
style: fix file frmating using prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Silent-Watcher committed Oct 18, 2023
1 parent dceaadc commit f96fd92
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

## [1.1.0](https://github.com/Silent-Watcher/jwt-node/compare/v1.0.0...v1.1.0) (2023-10-17)


### Features

* users can now login and fetch their jwt token from the response ([421a2f3](https://github.com/Silent-Watcher/jwt-node/commit/421a2f36a49b265654cf415dd52e1971111c7ad9))

- users can now login and fetch their jwt token from the response ([421a2f3](https://github.com/Silent-Watcher/jwt-node/commit/421a2f36a49b265654cf415dd52e1971111c7ad9))

### Bug Fixes

* fix file formating after running prettier package ([6c2cec4](https://github.com/Silent-Watcher/jwt-node/commit/6c2cec423819f2de493e012f0df0791762a01696))
- fix file formating after running prettier package ([6c2cec4](https://github.com/Silent-Watcher/jwt-node/commit/6c2cec423819f2de493e012f0df0791762a01696))

## 1.0.0 (2023-10-17)

Expand Down
4 changes: 2 additions & 2 deletions controllers/profile.controller.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

const indexProfileController = (req, res) => {
let user = req?.authenticated && req.user
let user = req?.authenticated && req.user;
res.status(200).send({
code: res.statusCode,
message: `hello ${user.fullname} welcome to your profile `,
user
user,
});
};

Expand Down
22 changes: 11 additions & 11 deletions middlewares/checkAuth.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const userModel = require('../models/user.model');
const { verifyToken } = require('../utils/auth.utils');

const checkAuth = async (req, res, next) => {
try {
try {
let authHeader = req?.headers?.authorization;
if (!authHeader) {
return res.status(403).json({
Expand All @@ -18,15 +18,15 @@ try {
if (bearer && bearer.toLowerCase() === 'bearer') {
if (token) {
let verifyResult = verifyToken(token);
const user = await userModel.findOne({ email: verifyResult.email });
const user = await userModel.findOne({
email: verifyResult.email,
});
req.authenticated = !!user;
if (!user)
return res
.status(404)
.send({
code: res.statusCode,
error: { message: 'invalid token' },
});
return res.status(404).send({
code: res.statusCode,
error: { message: 'invalid token' },
});
req.user = user;
return next();
}
Expand All @@ -37,9 +37,9 @@ try {
message: 'invalid credentials sent!',
},
};
} catch (error) {
next(error);
}
} catch (error) {
next(error);
}
};

module.exports = checkAuth;
6 changes: 2 additions & 4 deletions routes/profile.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ const { Router } = require('express');
const indexProfileController = require('../controllers/profile.controller');
const checkAuth = require('../middlewares/checkAuth.middleware');


const profileRouter = Router();

profileRouter.get('/', checkAuth ,indexProfileController);

profileRouter.get('/', checkAuth, indexProfileController);

module.exports = profileRouter;
module.exports = profileRouter;
2 changes: 0 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ app.use(router);
app.use(notFoundErrorHandler);
app.use(errorHandler);



server.listen(PORT, () =>
console.log(
`server is running on port : ${PORT},\n http://localhost:${PORT}`,
Expand Down

0 comments on commit f96fd92

Please sign in to comment.