Skip to content

Commit 1efd670

Browse files
VeryViciousTomek Piela
andauthored
feat: added context arg to authenticate method (#97)
Co-authored-by: Tomek Piela <[email protected]>
1 parent 1531b71 commit 1efd670

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/authentication/login.handler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import AdminJS from "adminjs";
22
import { Router } from "express";
33
import {
4+
AuthContext,
45
AuthenticationMaxRetriesOptions,
56
AuthenticationOptions,
67
} from "../types";
@@ -89,7 +90,8 @@ export const withLogin = (
8990
email: string;
9091
password: string;
9192
};
92-
const adminUser = await auth.authenticate(email, password);
93+
const context: AuthContext = { req, res };
94+
const adminUser = await auth.authenticate(email, password, context);
9395
if (adminUser) {
9496
req.session.adminUser = adminUser;
9597
req.session.save((err) => {

src/types.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Request, Response } from "express";
12
export type FormidableOptions = {
23
encoding?: string;
34
uploadDir?: string;
@@ -10,6 +11,17 @@ export type FormidableOptions = {
1011
multiples?: boolean;
1112
};
1213

14+
export type AuthenticationContext = {
15+
/**
16+
* @description Authentication request object
17+
*/
18+
req: Request;
19+
/**
20+
* @description Authentication response object
21+
*/
22+
res: Response;
23+
};
24+
1325
export type AuthenticationMaxRetriesOptions = {
1426
/**
1527
* @description Count of retries
@@ -24,7 +36,11 @@ export type AuthenticationMaxRetriesOptions = {
2436
export type AuthenticationOptions = {
2537
cookiePassword: string;
2638
cookieName?: string;
27-
authenticate: (email: string, password: string) => unknown | null;
39+
authenticate: (
40+
email: string,
41+
password: string,
42+
context?: AuthenticationContext
43+
) => unknown | null;
2844
/**
2945
* @description Maximum number of authorization attempts (if number - per minute)
3046
*/

0 commit comments

Comments
 (0)