auth-common 0.0.0-stage → 1.0.3
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 +2 -0
- package/build/index.js +2 -0
- package/build/middlewares/UserDetails.d.ts +16 -0
- package/build/middlewares/UserDetails.js +12 -0
- package/build/middlewares/ValidateUser.d.ts +2 -0
- package/build/middlewares/ValidateUser.js +8 -0
- package/package.json +31 -4
- package/README.md +0 -3
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace Express {
|
|
4
|
+
interface Request {
|
|
5
|
+
session?: {
|
|
6
|
+
token?: string;
|
|
7
|
+
};
|
|
8
|
+
currentUser?: {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
email: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export declare const userDetails: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
export const userDetails = async (req, res, next) => {
|
|
3
|
+
try {
|
|
4
|
+
const token = req?.session?.token;
|
|
5
|
+
const payload = jwt.verify(token, process.env.TOKEN_SECRET);
|
|
6
|
+
req.currentUser = payload;
|
|
7
|
+
next();
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
next(error);
|
|
11
|
+
}
|
|
12
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auth-common",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./build/index.js",
|
|
6
|
+
"types": "./build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"clean": "del-cli ./build/*",
|
|
12
|
+
"build": "npm run clean && tsc",
|
|
13
|
+
"pub": "git add . && git commit -m \"Updates\" && git push origin main && npm run build && npm version patch && npm publish "
|
|
14
|
+
},
|
|
15
|
+
"keywords": [],
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"type": "commonjs",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"del-cli": "^8.0.1",
|
|
21
|
+
"typescript": "^7.0.2"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@types/cookie-session": "^2.0.49",
|
|
25
|
+
"@types/express": "^5.0.6",
|
|
26
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
27
|
+
"cookie-session": "^2.1.1",
|
|
28
|
+
"error-common": "^1.0.3",
|
|
29
|
+
"express": "^5.3.0",
|
|
30
|
+
"express-validator": "^7.3.2",
|
|
31
|
+
"jsonwebtoken": "^9.0.3"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/README.md
DELETED