@doffy-gittix/common 1.0.6 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +0 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +0 -1
- package/build/index.js.map +1 -1
- package/build/middleware/get-current-user-handler.d.ts +2 -2
- package/build/middleware/get-current-user-handler.d.ts.map +1 -1
- package/build/middleware/get-current-user-handler.js +14 -4
- package/build/middleware/get-current-user-handler.js.map +1 -1
- package/package.json +31 -31
- package/build/config.d.ts +0 -4
- package/build/config.d.ts.map +0 -1
- package/build/config.js +0 -4
- package/build/config.js.map +0 -1
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
|
package/build/index.js
CHANGED
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
|
|
@@ -7,10 +7,10 @@ declare global {
|
|
|
7
7
|
namespace Express {
|
|
8
8
|
interface Request {
|
|
9
9
|
currentUser?: CurrentUser | null;
|
|
10
|
-
session?: Record<string, string
|
|
10
|
+
session?: Record<string, string> | null;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const useCurrentUserHandler: (config: Record<string, string>) => (req: Request, _res: Response, next: NextFunction) => void;
|
|
15
15
|
export {};
|
|
16
16
|
//# sourceMappingURL=get-current-user-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-current-user-handler.d.ts","sourceRoot":"","sources":["../../src/middleware/get-current-user-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"get-current-user-handler.d.ts","sourceRoot":"","sources":["../../src/middleware/get-current-user-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG/D,UAAU,WAAW;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,WAAW,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;YACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;SACzC;KACF;CACF;AAwBD,eAAO,MAAM,qBAAqB,GAChC,QAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,WAnBzB,OAAO,QACN,QAAQ,QACR,YAAY,SA0BnB,CAAC"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
let cookieName = '';
|
|
3
|
+
let jwtKey = '';
|
|
4
|
+
const getCurrentUserHandler = (req, _res, next) => {
|
|
5
|
+
const token = req.session?.[cookieName];
|
|
5
6
|
if (!token) {
|
|
6
7
|
req.currentUser = null;
|
|
7
8
|
return next();
|
|
8
9
|
}
|
|
9
10
|
try {
|
|
10
|
-
const verifiedUser = jwt.verify(token,
|
|
11
|
+
const verifiedUser = jwt.verify(token, jwtKey);
|
|
11
12
|
req.currentUser = verifiedUser;
|
|
12
13
|
}
|
|
13
14
|
catch (error) {
|
|
@@ -15,4 +16,13 @@ export const getCurrentUserHandler = (req, _res, next) => {
|
|
|
15
16
|
}
|
|
16
17
|
next();
|
|
17
18
|
};
|
|
19
|
+
export const useCurrentUserHandler = (config) => {
|
|
20
|
+
const { COOKIE_NAME, JWT_KEY } = config;
|
|
21
|
+
if (!COOKIE_NAME || !JWT_KEY) {
|
|
22
|
+
throw new Error('config required');
|
|
23
|
+
}
|
|
24
|
+
cookieName = COOKIE_NAME;
|
|
25
|
+
jwtKey = JWT_KEY;
|
|
26
|
+
return getCurrentUserHandler;
|
|
27
|
+
};
|
|
18
28
|
//# sourceMappingURL=get-current-user-handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-current-user-handler.js","sourceRoot":"","sources":["../../src/middleware/get-current-user-handler.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"get-current-user-handler.js","sourceRoot":"","sources":["../../src/middleware/get-current-user-handler.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,cAAc,CAAC;AAgB/B,IAAI,UAAU,GAAG,EAAE,CAAC;AACpB,IAAI,MAAM,GAAG,EAAE,CAAC;AAEhB,MAAM,qBAAqB,GAAG,CAC5B,GAAY,EACZ,IAAc,EACd,IAAkB,EAClB,EAAE;IACF,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,CAAC;IACxC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC;QACvB,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IACD,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAgB,CAAC;QAC9D,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC;IACzB,CAAC;IACD,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,MAA8B,EAC9B,EAAE;IACF,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACxC,IAAI,CAAC,WAAW,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,UAAU,GAAG,WAAW,CAAC;IACzB,MAAM,GAAG,OAAO,CAAC;IACjB,OAAO,qBAAqB,CAAC;AAC/B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@doffy-gittix/common",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "./build/index.js",
|
|
6
|
-
"types": "./build/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"build/**/*"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "del-cli build && tsc",
|
|
12
|
-
"pub": "npm version patch && git add . && git commit -m \"[upd] common\" && git push && npm publish"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [],
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "ISC",
|
|
17
|
-
"type": "module",
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"del-cli": "^7.0.0",
|
|
20
|
-
"typescript": "^6.0.3"
|
|
21
|
-
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@types/express": "^5.0.6",
|
|
24
|
-
"@types/express-validator": "^2.20.33",
|
|
25
|
-
"@types/jsonwebtoken": "^9.0.10",
|
|
26
|
-
"express": "^5.2.1",
|
|
27
|
-
"express-validator": "^7.3.2",
|
|
28
|
-
"jsonwebtoken": "^9.0.3",
|
|
29
|
-
"ts-node": "^10.9.2"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@doffy-gittix/common",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./build/index.js",
|
|
6
|
+
"types": "./build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "del-cli build && tsc",
|
|
12
|
+
"pub": "npm run build && npm version patch && git add . && git commit -m \"[upd] common\" && git push && npm publish"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"del-cli": "^7.0.0",
|
|
20
|
+
"typescript": "^6.0.3"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@types/express": "^5.0.6",
|
|
24
|
+
"@types/express-validator": "^2.20.33",
|
|
25
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
26
|
+
"express": "^5.2.1",
|
|
27
|
+
"express-validator": "^7.3.2",
|
|
28
|
+
"jsonwebtoken": "^9.0.3",
|
|
29
|
+
"ts-node": "^10.9.2"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/build/config.d.ts
DELETED
package/build/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,oBAA0B,CAAC;AACnD,eAAO,MAAM,UAAU,oBAAyB,CAAC;AACjD,eAAO,MAAM,OAAO,oBAAsB,CAAC"}
|
package/build/config.js
DELETED
package/build/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;AACnD,MAAM,CAAC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;AACjD,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC"}
|