Skip to content

Commit

Permalink
[FIX]: token validation
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaryoshida committed Nov 22, 2023
1 parent 00a9396 commit a6a7746
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
1 change: 1 addition & 0 deletions backend/controllers/UserControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exports.userLogin = async(req, res) => {
res.cookie('access-token', accessToken, {
maxAge: 2592000000,
httpOnly: true,
secure: true,
});
Users.update(
{ token: accessToken },
Expand Down
4 changes: 0 additions & 4 deletions backend/controllers/middlewares/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ const createToken = (user) => {
};

const validateToken = (req, res, next) => {

if (req.path === '/auth/register' && req.method === 'POST') {
return next();
}

const accessToken = req.cookies && req.cookies['access-token'];
if (!accessToken) {
Expand Down
2 changes: 0 additions & 2 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { validateToken } = require('./controllers/middlewares/Auth');
const express = require('express');
const database = require('./models/schemas');
const userRoute = require('./views/routes/Users');
Expand All @@ -9,7 +8,6 @@ require("dotenv").config();
const app = express();
const port = 3001;
app.use(express.json());
app.use(validateToken);

app.use('/auth', userRoute);
app.use('/elective', electiveRoute);
Expand Down
9 changes: 5 additions & 4 deletions backend/views/routes/Users.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const express = require('express');
const router = express.Router();
const cookieParser = require('cookie-parser');
const userController = require('../../controllers/UserControllers');
const userController = require('../../controllers/UserControllers');
const { validateToken } = require('../../controllers/middlewares/Auth');

router.use(cookieParser());
router.post('/register', userController.userRegister);
router.post('/login', userController.userLogin);

router.get('/profile', validateToken, (req, res) => {
res.json('profile');
});

module.exports = router;
router.post('/register', userController.userRegister);
router.post('/login', userController.userLogin);

module.exports = router;

0 comments on commit a6a7746

Please sign in to comment.