response-standardizer 1.0.8 → 1.1.0
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/index.js +1 -1
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
- package/src/index.ts +5 -5
- package/src/types.ts +5 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm publish --access public
|
package/dist/index.js
CHANGED
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,8 +1,8 @@
|
|
|
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
|
-
import jwt from "jsonwebtoken";
|
|
5
|
+
import jwt, { TokenExpiredError } from "jsonwebtoken";
|
|
6
6
|
import path from "path";
|
|
7
7
|
declare global {
|
|
8
8
|
namespace Express {
|
|
@@ -39,14 +39,14 @@ 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
|
|
|
47
47
|
next();
|
|
48
48
|
} catch (err) {
|
|
49
|
-
|
|
49
|
+
error((err as any)?.message)
|
|
50
50
|
return RestResponse.unauthorized(req, res, "Token is not valid")
|
|
51
51
|
}
|
|
52
52
|
}
|
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
|
+
}
|