|
1 |
| -import { Request, Response, NextFunction } from 'express'; |
2 |
| -import { Session } from 'express-session'; |
3 |
| -import { generate2FACode, verify2FACode } from '../services/2fa.service'; |
| 1 | +// import { Request, Response, NextFunction } from 'express'; |
| 2 | +// import { Session } from 'express-session'; |
| 3 | +// import { generate2FACode, verify2FACode } from '../services/2fa.service'; |
4 | 4 |
|
5 |
| -interface ExtendedSession extends Session { |
6 |
| - email?: string; |
7 |
| - password?: string; |
8 |
| - twoFactorCode?: string | null; |
9 |
| - twoFactorExpiry?: Date | null; |
10 |
| - twoFAError?: string; |
11 |
| -} |
| 5 | +// interface ExtendedSession extends Session { |
| 6 | +// email?: string; |
| 7 | +// password?: string; |
| 8 | +// twoFactorCode?: string | null; |
| 9 | +// twoFactorExpiry?: Date | null; |
| 10 | +// twoFAError?: string; |
| 11 | +// } |
12 | 12 |
|
13 |
| -interface ExtendedRequest extends Request { |
14 |
| - session: ExtendedSession; |
15 |
| -} |
| 13 | +// interface ExtendedRequest extends Request { |
| 14 | +// session: ExtendedSession; |
| 15 | +// } |
16 | 16 |
|
17 |
| -export const twoFAController = async ( |
18 |
| - req: ExtendedRequest, |
19 |
| - res: Response, |
20 |
| - next: NextFunction |
21 |
| -) => { |
22 |
| - const { email, password } = req.body; |
23 |
| - const twoFactorData = await generate2FACode(req.body); |
24 |
| - const extSession = req.session; |
| 17 | +// export const twoFAController = async ( |
| 18 | +// req: ExtendedRequest, |
| 19 | +// res: Response, |
| 20 | +// next: NextFunction |
| 21 | +// ) => { |
| 22 | +// const { email, password } = req.body; |
| 23 | +// const twoFactorData = await generate2FACode(req.body); |
| 24 | +// const extSession = req.session; |
25 | 25 |
|
26 |
| - if (twoFactorData) { |
27 |
| - extSession.twoFactorCode = twoFactorData.twoFactorCode; |
28 |
| - if (typeof twoFactorData.twoFactorExpiry === 'number') { |
29 |
| - extSession.twoFactorExpiry = new Date(twoFactorData.twoFactorExpiry); |
30 |
| - } |
31 |
| - extSession.email = email; |
32 |
| - extSession.password = password; |
33 |
| - return res.status(200).json({ message: '2FA code sent. Please verify the code.' }); |
34 |
| - } else { |
35 |
| - next(); |
36 |
| - } |
37 |
| -}; |
| 26 | +// if (twoFactorData) { |
| 27 | +// extSession.twoFactorCode = twoFactorData.twoFactorCode; |
| 28 | +// if (typeof twoFactorData.twoFactorExpiry === 'number') { |
| 29 | +// extSession.twoFactorExpiry = new Date(twoFactorData.twoFactorExpiry); |
| 30 | +// } |
| 31 | +// extSession.email = email; |
| 32 | +// extSession.password = password; |
| 33 | +// return res.status(200).json({ message: '2FA code sent. Please verify the code.' }); |
| 34 | +// } else { |
| 35 | +// next(); |
| 36 | +// } |
| 37 | +// }; |
38 | 38 |
|
39 |
| -export const verifyCode = async ( |
40 |
| - req: ExtendedRequest, |
41 |
| - res: Response, |
42 |
| - next: NextFunction |
43 |
| -) => { |
44 |
| - const extendedSession = req.session; |
45 |
| - const { code } = req.body; |
| 39 | +// export const verifyCode = async ( |
| 40 | +// req: ExtendedRequest, |
| 41 | +// res: Response, |
| 42 | +// next: NextFunction |
| 43 | +// ) => { |
| 44 | +// const extendedSession = req.session; |
| 45 | +// const { code } = req.body; |
46 | 46 |
|
47 |
| - const sessionCode = extendedSession.twoFactorCode; |
48 |
| - const sessionExpiry = extendedSession.twoFactorExpiry; |
| 47 | +// const sessionCode = extendedSession.twoFactorCode; |
| 48 | +// const sessionExpiry = extendedSession.twoFactorExpiry; |
49 | 49 |
|
50 |
| - if (sessionCode && sessionExpiry) { |
51 |
| - const sessionExpiryDate = new Date(sessionExpiry); |
| 50 | +// if (sessionCode && sessionExpiry) { |
| 51 | +// const sessionExpiryDate = new Date(sessionExpiry); |
52 | 52 |
|
53 |
| - if (verify2FACode(code, sessionCode, sessionExpiryDate.getTime())) { |
54 |
| - extendedSession.twoFactorCode = null; |
55 |
| - extendedSession.twoFactorExpiry = null; |
56 |
| - } else { |
57 |
| - extendedSession.twoFAError = 'Invalid or expired 2FA code.'; |
58 |
| - } |
59 |
| - } else { |
60 |
| - extendedSession.twoFAError = '2FA code or expiring time is missing.'; |
61 |
| - } |
| 53 | +// if (verify2FACode(code, sessionCode, sessionExpiryDate.getTime())) { |
| 54 | +// extendedSession.twoFactorCode = null; |
| 55 | +// extendedSession.twoFactorExpiry = null; |
| 56 | +// } else { |
| 57 | +// extendedSession.twoFAError = 'Invalid or expired 2FA code.'; |
| 58 | +// } |
| 59 | +// } else { |
| 60 | +// extendedSession.twoFAError = '2FA code or expiring time is missing.'; |
| 61 | +// } |
62 | 62 |
|
63 |
| - try { |
64 |
| - await new Promise<void>((resolve, reject) => { |
65 |
| - req.session.save((err) => { |
66 |
| - if (err) { |
67 |
| - reject(err); |
68 |
| - } else { |
69 |
| - resolve(); |
70 |
| - } |
71 |
| - }); |
72 |
| - }); |
73 |
| - next(); |
74 |
| - } catch (err) { |
75 |
| - return res.status(500).json({ message: 'Error saving session' }); |
76 |
| - } |
77 |
| -}; |
| 63 | +// try { |
| 64 | +// await new Promise<void>((resolve, reject) => { |
| 65 | +// req.session.save((err) => { |
| 66 | +// if (err) { |
| 67 | +// reject(err); |
| 68 | +// } else { |
| 69 | +// resolve(); |
| 70 | +// } |
| 71 | +// }); |
| 72 | +// }); |
| 73 | +// next(); |
| 74 | +// } catch (err) { |
| 75 | +// return res.status(500).json({ message: 'Error saving session' }); |
| 76 | +// } |
| 77 | +// }; |
0 commit comments