response-standardizer 1.0.8 → 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/README.md +1 -0
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
- package/src/index.ts +3 -3
- package/src/types.ts +5 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm publish --access public
|
package/dist/types.d.ts
CHANGED
|
@@ -32,3 +32,7 @@ export interface RestResponseFunctions {
|
|
|
32
32
|
unauthorized: (req: Request, res: Response, message?: string) => void;
|
|
33
33
|
accessDenied: (req: Request, res: Response, message?: string) => void;
|
|
34
34
|
}
|
|
35
|
+
export interface AuthRequest extends Request {
|
|
36
|
+
user?: any;
|
|
37
|
+
token?: string;
|
|
38
|
+
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
import { ErrorFields, PaginationMeta, StandardResponse, RestResponseFunctions, RestMiddlewareFunctions } from "./types.js";
|
|
2
|
+
import { ErrorFields, PaginationMeta, StandardResponse, RestResponseFunctions, RestMiddlewareFunctions, AuthRequest } from "./types.js";
|
|
3
3
|
import { generateRequestId, getTimestamp } from "./utils.js";
|
|
4
4
|
import axios from "axios";
|
|
5
5
|
import jwt from "jsonwebtoken";
|
|
@@ -39,8 +39,8 @@ export const protect = (allowedRoles?: string[]) => {
|
|
|
39
39
|
|
|
40
40
|
try {
|
|
41
41
|
const decoded = jwt.verify(token, KEYCLOAK_PUBLIC_KEY, { algorithms: ["RS256"] });
|
|
42
|
-
(req as
|
|
43
|
-
(req as
|
|
42
|
+
(req as AuthRequest).user = decoded;
|
|
43
|
+
(req as AuthRequest).token = token;
|
|
44
44
|
if(allowedRoles)
|
|
45
45
|
return role(req, res, next, allowedRoles);
|
|
46
46
|
|
package/src/types.ts
CHANGED
|
@@ -53,3 +53,8 @@ export interface RestResponseFunctions {
|
|
|
53
53
|
unauthorized: (req: Request, res: Response, message?: string) => void;
|
|
54
54
|
accessDenied: (req: Request, res: Response, message?: string) => void;
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
export interface AuthRequest extends Request {
|
|
58
|
+
user?: any;
|
|
59
|
+
token?: string
|
|
60
|
+
}
|