@meridianjs/auth 0.1.10 → 0.1.12

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/dist/index.d.mts CHANGED
@@ -127,10 +127,11 @@ declare function requireRoles(...roles: string[]): (req: any, res: Response, nex
127
127
  declare function requirePermission(...permissions: string[]): (req: any, res: Response, next: NextFunction) => void;
128
128
  /**
129
129
  * Workspace isolation guard — rejects requests where the `workspace_id` query
130
- * param or body field does not match the authenticated user's workspace.
130
+ * param, body field, or URL path param (:id on /workspaces/:id sub-routes)
131
+ * does not match the authenticated user's workspace.
131
132
  *
132
- * Allows the request through when no `workspace_id` is present (so general
133
- * listing endpoints that omit workspace_id are not blocked).
133
+ * Allows the request through when no workspace identifier is present (so
134
+ * general listing endpoints that omit workspace_id are not blocked).
134
135
  *
135
136
  * Must be used after `authenticateJWT`.
136
137
  */
package/dist/index.d.ts CHANGED
@@ -127,10 +127,11 @@ declare function requireRoles(...roles: string[]): (req: any, res: Response, nex
127
127
  declare function requirePermission(...permissions: string[]): (req: any, res: Response, next: NextFunction) => void;
128
128
  /**
129
129
  * Workspace isolation guard — rejects requests where the `workspace_id` query
130
- * param or body field does not match the authenticated user's workspace.
130
+ * param, body field, or URL path param (:id on /workspaces/:id sub-routes)
131
+ * does not match the authenticated user's workspace.
131
132
  *
132
- * Allows the request through when no `workspace_id` is present (so general
133
- * listing endpoints that omit workspace_id are not blocked).
133
+ * Allows the request through when no workspace identifier is present (so
134
+ * general listing endpoints that omit workspace_id are not blocked).
134
135
  *
135
136
  * Must be used after `authenticateJWT`.
136
137
  */
package/dist/index.js CHANGED
@@ -248,6 +248,8 @@ var AuthModuleService = class extends (0, import_framework_utils.MeridianService
248
248
  const userService = this.container.resolve("userModuleService");
249
249
  const password_hash = await import_bcrypt.default.hash(newPassword, BCRYPT_ROUNDS);
250
250
  await userService.updateUser(userId, { password_hash, has_password: true });
251
+ await userService.revokeAllUserSessions(userId).catch(() => {
252
+ });
251
253
  }
252
254
  /**
253
255
  * Generate a password reset token for the given email.
@@ -343,7 +345,15 @@ function authenticateJWT(req, res, next) {
343
345
  res.status(401).json({ error: { message: "Session revoked or expired" } });
344
346
  return;
345
347
  }
346
- } catch {
348
+ } catch (sessionErr) {
349
+ try {
350
+ const scope = req.scope;
351
+ const logger = scope.resolve("logger");
352
+ logger.warn(`[auth] jti session check failed: ${sessionErr instanceof Error ? sessionErr.message : String(sessionErr)}`);
353
+ } catch {
354
+ }
355
+ res.status(401).json({ error: { message: "Session validation unavailable" } });
356
+ return;
347
357
  }
348
358
  }
349
359
  req.user = {
@@ -378,8 +388,11 @@ function requirePermission(...permissions) {
378
388
  };
379
389
  }
380
390
  function requireWorkspace(req, res, next) {
381
- const workspaceId = req.query?.workspace_id ?? req.body?.workspace_id;
382
- if (workspaceId && req.user?.workspaceId && req.user.workspaceId !== workspaceId) {
391
+ const queryOrBodyId = req.query?.workspace_id ?? req.body?.workspace_id;
392
+ const isWorkspacePath = /\/workspaces\/[^/]/.test(req.path ?? req.url ?? "");
393
+ const paramId = isWorkspacePath ? req.params?.workspaceId ?? req.params?.id : void 0;
394
+ const requestedId = queryOrBodyId ?? paramId;
395
+ if (requestedId && req.user?.workspaceId && req.user.workspaceId !== requestedId) {
383
396
  return res.status(403).json({ error: { message: "Forbidden \u2014 wrong workspace" } });
384
397
  }
385
398
  next();
package/dist/index.mjs CHANGED
@@ -208,6 +208,8 @@ var AuthModuleService = class extends MeridianService({}) {
208
208
  const userService = this.container.resolve("userModuleService");
209
209
  const password_hash = await bcrypt.hash(newPassword, BCRYPT_ROUNDS);
210
210
  await userService.updateUser(userId, { password_hash, has_password: true });
211
+ await userService.revokeAllUserSessions(userId).catch(() => {
212
+ });
211
213
  }
212
214
  /**
213
215
  * Generate a password reset token for the given email.
@@ -303,7 +305,15 @@ function authenticateJWT(req, res, next) {
303
305
  res.status(401).json({ error: { message: "Session revoked or expired" } });
304
306
  return;
305
307
  }
306
- } catch {
308
+ } catch (sessionErr) {
309
+ try {
310
+ const scope = req.scope;
311
+ const logger = scope.resolve("logger");
312
+ logger.warn(`[auth] jti session check failed: ${sessionErr instanceof Error ? sessionErr.message : String(sessionErr)}`);
313
+ } catch {
314
+ }
315
+ res.status(401).json({ error: { message: "Session validation unavailable" } });
316
+ return;
307
317
  }
308
318
  }
309
319
  req.user = {
@@ -338,8 +348,11 @@ function requirePermission(...permissions) {
338
348
  };
339
349
  }
340
350
  function requireWorkspace(req, res, next) {
341
- const workspaceId = req.query?.workspace_id ?? req.body?.workspace_id;
342
- if (workspaceId && req.user?.workspaceId && req.user.workspaceId !== workspaceId) {
351
+ const queryOrBodyId = req.query?.workspace_id ?? req.body?.workspace_id;
352
+ const isWorkspacePath = /\/workspaces\/[^/]/.test(req.path ?? req.url ?? "");
353
+ const paramId = isWorkspacePath ? req.params?.workspaceId ?? req.params?.id : void 0;
354
+ const requestedId = queryOrBodyId ?? paramId;
355
+ if (requestedId && req.user?.workspaceId && req.user.workspaceId !== requestedId) {
343
356
  return res.status(403).json({ error: { message: "Forbidden \u2014 wrong workspace" } });
344
357
  }
345
358
  next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meridianjs/auth",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Meridian auth module — JWT authentication and middleware",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",