auth-common 1.0.5 → 1.0.7

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 CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./middlewares/UserDetails";
2
2
  export * from "./middlewares/ValidateUser";
3
+ export * from "./middlewares/ValidAdmin";
package/build/index.js CHANGED
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./middlewares/UserDetails"), exports);
18
18
  __exportStar(require("./middlewares/ValidateUser"), exports);
19
+ __exportStar(require("./middlewares/ValidAdmin"), exports);
@@ -9,7 +9,8 @@ declare global {
9
9
  id: string;
10
10
  name: string;
11
11
  email: string;
12
- };
12
+ role: string;
13
+ } | null;
13
14
  }
14
15
  }
15
16
  }
@@ -0,0 +1,2 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+ export declare const ValidAdmin: (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidAdmin = void 0;
4
+ const error_common_1 = require("error-common");
5
+ const ValidAdmin = async (req, res, next) => {
6
+ try {
7
+ const currentUser = req.currentUser;
8
+ console.log("Current User details", currentUser);
9
+ if (currentUser?.role !== "admin") {
10
+ throw new error_common_1.CommonError("Admin access required");
11
+ }
12
+ next();
13
+ }
14
+ catch (err) {
15
+ next(err); // forwards errors to your error handler instead of hanging
16
+ }
17
+ };
18
+ exports.ValidAdmin = ValidAdmin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auth-common",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",