diff --git a/src/middleware/2fa.middleware.ts b/src/middleware/2fa.middleware.ts index 8aee7ae..a19544d 100644 --- a/src/middleware/2fa.middleware.ts +++ b/src/middleware/2fa.middleware.ts @@ -1,77 +1,77 @@ -import { Request, Response, NextFunction } from 'express'; -import { Session } from 'express-session'; -import { generate2FACode, verify2FACode } from '../services/2fa.service'; +// import { Request, Response, NextFunction } from 'express'; +// import { Session } from 'express-session'; +// import { generate2FACode, verify2FACode } from '../services/2fa.service'; -interface ExtendedSession extends Session { - email?: string; - password?: string; - twoFactorCode?: string | null; - twoFactorExpiry?: Date | null; - twoFAError?: string; -} +// interface ExtendedSession extends Session { +// email?: string; +// password?: string; +// twoFactorCode?: string | null; +// twoFactorExpiry?: Date | null; +// twoFAError?: string; +// } -interface ExtendedRequest extends Request { - session: ExtendedSession; -} +// interface ExtendedRequest extends Request { +// session: ExtendedSession; +// } -export const twoFAController = async ( - req: ExtendedRequest, - res: Response, - next: NextFunction -) => { - const { email, password } = req.body; - const twoFactorData = await generate2FACode(req.body); - const extSession = req.session; +// export const twoFAController = async ( +// req: ExtendedRequest, +// res: Response, +// next: NextFunction +// ) => { +// const { email, password } = req.body; +// const twoFactorData = await generate2FACode(req.body); +// const extSession = req.session; - if (twoFactorData) { - extSession.twoFactorCode = twoFactorData.twoFactorCode; - if (typeof twoFactorData.twoFactorExpiry === 'number') { - extSession.twoFactorExpiry = new Date(twoFactorData.twoFactorExpiry); - } - extSession.email = email; - extSession.password = password; - return res.status(200).json({ message: '2FA code sent. Please verify the code.' }); - } else { - next(); - } -}; +// if (twoFactorData) { +// extSession.twoFactorCode = twoFactorData.twoFactorCode; +// if (typeof twoFactorData.twoFactorExpiry === 'number') { +// extSession.twoFactorExpiry = new Date(twoFactorData.twoFactorExpiry); +// } +// extSession.email = email; +// extSession.password = password; +// return res.status(200).json({ message: '2FA code sent. Please verify the code.' }); +// } else { +// next(); +// } +// }; -export const verifyCode = async ( - req: ExtendedRequest, - res: Response, - next: NextFunction -) => { - const extendedSession = req.session; - const { code } = req.body; +// export const verifyCode = async ( +// req: ExtendedRequest, +// res: Response, +// next: NextFunction +// ) => { +// const extendedSession = req.session; +// const { code } = req.body; - const sessionCode = extendedSession.twoFactorCode; - const sessionExpiry = extendedSession.twoFactorExpiry; +// const sessionCode = extendedSession.twoFactorCode; +// const sessionExpiry = extendedSession.twoFactorExpiry; - if (sessionCode && sessionExpiry) { - const sessionExpiryDate = new Date(sessionExpiry); +// if (sessionCode && sessionExpiry) { +// const sessionExpiryDate = new Date(sessionExpiry); - if (verify2FACode(code, sessionCode, sessionExpiryDate.getTime())) { - extendedSession.twoFactorCode = null; - extendedSession.twoFactorExpiry = null; - } else { - extendedSession.twoFAError = 'Invalid or expired 2FA code.'; - } - } else { - extendedSession.twoFAError = '2FA code or expiring time is missing.'; - } +// if (verify2FACode(code, sessionCode, sessionExpiryDate.getTime())) { +// extendedSession.twoFactorCode = null; +// extendedSession.twoFactorExpiry = null; +// } else { +// extendedSession.twoFAError = 'Invalid or expired 2FA code.'; +// } +// } else { +// extendedSession.twoFAError = '2FA code or expiring time is missing.'; +// } - try { - await new Promise((resolve, reject) => { - req.session.save((err) => { - if (err) { - reject(err); - } else { - resolve(); - } - }); - }); - next(); - } catch (err) { - return res.status(500).json({ message: 'Error saving session' }); - } -}; +// try { +// await new Promise((resolve, reject) => { +// req.session.save((err) => { +// if (err) { +// reject(err); +// } else { +// resolve(); +// } +// }); +// }); +// next(); +// } catch (err) { +// return res.status(500).json({ message: 'Error saving session' }); +// } +// }; diff --git a/src/routes/2fa.route.ts b/src/routes/2fa.route.ts index 248ad29..0292874 100644 --- a/src/routes/2fa.route.ts +++ b/src/routes/2fa.route.ts @@ -1,12 +1,12 @@ -import { Router } from "express"; -import { enable2FA } from "../controllers/2fa.controller"; -import { VerifyAccessToken } from "../middleware/verfiyToken"; -import { verifyCode } from "./../middleware/2fa.middleware"; -import { login } from "../controllers/user.controller"; +// import { Router } from "express"; +// import { enable2FA } from "../controllers/2fa.controller"; +// import { VerifyAccessToken } from "../middleware/verfiyToken"; +// import { verifyCode } from "./../middleware/2fa.middleware"; +// import { login } from "../controllers/user.controller"; -const router = Router(); +// const router = Router(); -router.post("/enable-2fa", VerifyAccessToken, enable2FA); -router.post("/verify-code", verifyCode, login); +// router.post("/enable-2fa", VerifyAccessToken, enable2FA); +// router.post("/verify-code", verifyCode, login); -export default router; +// export default router; diff --git a/src/routes/user.route.ts b/src/routes/user.route.ts index 675d985..f96ce8a 100644 --- a/src/routes/user.route.ts +++ b/src/routes/user.route.ts @@ -1,4 +1,4 @@ -import { twoFAController } from "./../middleware/2fa.middleware"; + import express,{Request,Response} from "express"; import { @@ -30,7 +30,7 @@ route.post("/register", register); route.patch("/updateuser/:id", editUser); route.patch("/updatepassword/:id", updatePassword); route.delete("/deleteuser/:id", VerifyAccessToken, deleteUser); -route.post("/login", twoFAController, login); +route.post("/login", login); route.post("/addreview/:id", addReview); route.post("/addfeedback/:id", addFeedback);