@sendhome/common 1.0.153 → 1.0.155

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.
@@ -2,6 +2,7 @@ import { Request, Response, NextFunction } from 'express';
2
2
  interface UserPayload {
3
3
  id: string;
4
4
  email: string;
5
+ sessionId: string;
5
6
  }
6
7
  declare global {
7
8
  namespace Express {
@@ -2,6 +2,7 @@ import { Request, Response, NextFunction } from 'express';
2
2
  interface UserPayload {
3
3
  id: string;
4
4
  email: string;
5
+ sessionId: string;
5
6
  }
6
7
  declare global {
7
8
  namespace Express {
@@ -2,6 +2,7 @@ import { Request, Response, NextFunction } from 'express';
2
2
  interface UserPayload {
3
3
  id: string;
4
4
  email: string;
5
+ sessionId: string;
5
6
  }
6
7
  declare global {
7
8
  namespace Express {
@@ -10,5 +11,5 @@ declare global {
10
11
  }
11
12
  }
12
13
  }
13
- export declare const validateSession: (sessionServiceUrl: string, deviceInfo: string) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
14
+ export declare const requireAuth: (sessionServiceUrl: string, deviceInfo: string) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
14
15
  export {};
@@ -12,11 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.validateSession = void 0;
15
+ exports.requireAuth = void 0;
16
16
  const axios_1 = __importDefault(require("axios"));
17
17
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
18
18
  // Middleware to validate user session per device
19
- const validateSession = (sessionServiceUrl, deviceInfo) => {
19
+ const requireAuth = (sessionServiceUrl, deviceInfo) => {
20
20
  return (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
21
21
  var _a;
22
22
  try {
@@ -29,9 +29,7 @@ const validateSession = (sessionServiceUrl, deviceInfo) => {
29
29
  // process.env.JWT_KEY!
30
30
  );
31
31
  // Call the session service to validate the session
32
- const response = yield axios_1.default.get(`${sessionServiceUrl}/api/validate-session/${payload.id}`, {
33
- params: { device_info: deviceInfo }, // Send the device info for validation
34
- });
32
+ const response = yield axios_1.default.get(`${sessionServiceUrl}/${payload.sessionId}`);
35
33
  if (response.status !== 200) {
36
34
  res.status(401).json({ message: 'Invalid or expired session' });
37
35
  return;
@@ -45,4 +43,4 @@ const validateSession = (sessionServiceUrl, deviceInfo) => {
45
43
  }
46
44
  });
47
45
  };
48
- exports.validateSession = validateSession;
46
+ exports.requireAuth = requireAuth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendhome/common",
3
- "version": "1.0.153",
3
+ "version": "1.0.155",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",