Skip to content

Commit

Permalink
fix jwt auth
Browse files Browse the repository at this point in the history
  • Loading branch information
moshrepo00 committed Jun 7, 2019
1 parent dd52342 commit 073299c
Show file tree
Hide file tree
Showing 49 changed files with 14 additions and 12 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 1 addition & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ app.use((req, res, next) => {
app.use('/currency', currencyConverterRoutes);
app.use('/auth', authRoutes);

app.get('/', (req, res) => {
res.send('Server is running');
});

app.use((error, req, res, next) => {
console.log(error.statusCode);
const status = error.statusCode || 500;
const message = error.message;
const data = error.data;
Expand Down
8 changes: 6 additions & 2 deletions controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ exports.signup = (req, res, next) => {
firstName: req.body.firstName,
lastName: req.body.lastName,
email: req.body.email,
hash_password: hashedPw,
image: req.file.path
hash_password: hashedPw
});

if (req.file) {
user.image = req.file.path;
}

return user.save();
})
.then((user) => {
Expand Down
2 changes: 1 addition & 1 deletion controllers/curr-converter.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports.getConversion = (req, res, next) => {

rp(requestOptions)
.then((response) => {
console.log('API call response:', response);
// console.log('API call response:', response);
res.json(response);
})
.catch((err) => {
Expand Down
Binary file added images/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed images/2019-05-15T16:41:47.069Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-15T16:47:03.723Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-15T16:48:48.790Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-15T16:50:04.065Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-16T15:32:37.912Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-16T17:18:59.280Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-16T17:20:14.062Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-16T17:21:40.625Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-16T17:22:34.867Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-18T09:48:16.078Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-18T09:49:38.627Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-18T10:01:27.931Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-18T10:02:00.065Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-18T10:02:34.040Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-18T11:09:32.688Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-18T11:12:16.193Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-18T11:21:24.487Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-19T06:20:02.726Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-19T06:43:01.748Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-19T08:36:31.359Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-19T08:37:34.358Z-app-image.png
Binary file not shown.
Binary file removed images/2019-05-19T08:38:29.046Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:38:30.613Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:38:31.869Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:38:59.744Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:39:01.372Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:39:02.294Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:39:13.522Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:39:14.784Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:40:32.232Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:40:54.474Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:41:23.075Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:41:24.358Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T08:42:16.049Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T10:39:23.302Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T11:16:15.491Z-app-image.png
Diff not rendered.
Binary file removed images/2019-05-19T11:16:44.261Z-app-image.png
Diff not rendered.
6 changes: 3 additions & 3 deletions middleware/auth/is-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ exports.isLoggedIn = (req, res, next) => {
const token = authHeader.split(' ')[1];
let decodedToken;
try {
decodedToken = jwt.verify(token, config.js);
decodedToken = jwt.verify(token, config.secret);
} catch (err) {
err.statusCode = 500;
throw error;
err.statusCode = 403;
throw err;
}
req.userId = decodedToken.userId;
next();
Expand Down
2 changes: 1 addition & 1 deletion models/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let UserSchema = new Schema({
lastName: { type: String, required: true },
email: { type: String, required: true },
hash_password: { type: String, required: true },
image: { type: String, required: true }
image: { type: String, required: false }
});

// Export the model
Expand Down
3 changes: 2 additions & 1 deletion routes/curr-converter.route.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const express = require('express');
const router = express.Router();
const currencyController = require('../controllers/curr-converter.controller');
const { isLoggedIn } = require('../middleware/auth/is-auth');

router.get('/', currencyController.getConversion);
router.get('/', isLoggedIn, currencyController.getConversion);

module.exports = router;

0 comments on commit 073299c

Please sign in to comment.