diff --git a/middleware/checkAuthenticated.js b/miscellaneous/checkAuthenticated.ts similarity index 60% rename from middleware/checkAuthenticated.js rename to miscellaneous/checkAuthenticated.ts index af6aa53..9545479 100644 --- a/middleware/checkAuthenticated.js +++ b/miscellaneous/checkAuthenticated.ts @@ -1,7 +1,8 @@ +import { type Express, type NextFunction, type Request, type Response } from "express"; +import UserModel from '../models/userModel'; -var UserModel = require('../models/userModel'); -async function checkAuthenticated(req, res, next) { +async function checkAuthenticated(req: Request, res: Response, next: NextFunction) { try { const password = req.body.pass; const userFound = await UserModel.findOne({ pass: password }); @@ -16,4 +17,4 @@ async function checkAuthenticated(req, res, next) { } } -module.exports = checkAuthenticated; \ No newline at end of file +export default checkAuthenticated; \ No newline at end of file diff --git a/miscellaneous/custom.d.ts b/miscellaneous/custom.d.ts new file mode 100644 index 0000000..f412d8e --- /dev/null +++ b/miscellaneous/custom.d.ts @@ -0,0 +1,13 @@ + + +declare namespace Express { + export interface Request { + user?: Document + } +} \ No newline at end of file diff --git a/routes/api/apiRouter.js b/routes/api/apiRouter.js index 5b4cd75..d742c64 100644 --- a/routes/api/apiRouter.js +++ b/routes/api/apiRouter.js @@ -1,6 +1,6 @@ var express = require('express'); var router = express.Router(); -const checkAuthenticated = require('../../middleware/checkAuthenticated.js'); +const checkAuthenticated = require('../../miscellaneous/checkAuthenticated.js').default; var mediaRouter = require('./mediaRouter'); var gameRouter = require('./gameRouter'); diff --git a/routes/api/gameRouter.js b/routes/api/gameRouter.js index 0665ad4..b28d482 100644 --- a/routes/api/gameRouter.js +++ b/routes/api/gameRouter.js @@ -1,7 +1,7 @@ var express = require('express'); var router = express.Router(); var gameController = require('../../controllers/gameController.js'); -var checkAuthenticated = require('../../middleware/checkAuthenticated.js'); +var checkAuthenticated = require('../../miscellaneous/checkAuthenticated.js').default; router.get('/', gameController.list); diff --git a/routes/api/mediaRouter.js b/routes/api/mediaRouter.js index 3f15bc1..dccd67a 100644 --- a/routes/api/mediaRouter.js +++ b/routes/api/mediaRouter.js @@ -1,7 +1,7 @@ var express = require('express'); var router = express.Router(); var mediaController = require('../../controllers/mediaController.js'); -var checkAuthenticated = require('../../middleware/checkAuthenticated.js'); +var checkAuthenticated = require('../../miscellaneous/checkAuthenticated.js').default; router.get('/', mediaController.list); diff --git a/routes/user.js b/routes/user.js index 16f6570..8d16980 100644 --- a/routes/user.js +++ b/routes/user.js @@ -1,7 +1,7 @@ var express = require('express'); var router = express.Router(); var userController = require('../controllers/userController.js'); -const checkAuthenticated = require('../middleware/checkAuthenticated.js'); +const checkAuthenticated = require('../miscellaneous/checkAuthenticated.js').default; /* GET home page. */ router.get('/', function (req, res, next) {