Skip to content

Commit

Permalink
Add sessiom request types
Browse files Browse the repository at this point in the history
  • Loading branch information
sevelinCa committed Jul 21, 2024
1 parent 8f4e01e commit 86d32f9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/middleware/2fa.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Request, Response, NextFunction } from "express";
import { Session } from "express-session";
import { generate2FACode } from "../services/2fa.service";
import { verify2FACode } from "../services/2fa.service";
import { generate2FACode, verify2FACode } from "../services/2fa.service";

// Extend the Session interface
interface ExtendedSession extends Session {
email?: string;
password?: string;
Expand All @@ -11,14 +11,19 @@ interface ExtendedSession extends Session {
twoFAError?: string;
}

// Extend the Request interface
interface ExtendedRequest extends Request {
session: ExtendedSession;
}

export const twoFAController = async (
req: Request,
req: ExtendedRequest,
res: Response,
next: NextFunction
) => {
const { email, password } = req.body;
const twoFactorData = await generate2FACode(req.body);
const extSession = req.session as ExtendedSession;
const extSession = req.session;

if (twoFactorData) {
extSession.twoFactorCode = twoFactorData.twoFactorCode;
Expand All @@ -34,11 +39,11 @@ export const twoFAController = async (
};

export const verifyCode = async (
req: Request,
req: ExtendedRequest,
res: Response,
next: NextFunction
) => {
const extendedSession = req.session as ExtendedSession;
const extendedSession = req.session;
const { code } = req.body;

const sessionCode = extendedSession.twoFactorCode;
Expand Down

0 comments on commit 86d32f9

Please sign in to comment.