@meridianjs/auth 1.31.0 → 2.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/dist/index.d.mts CHANGED
@@ -94,6 +94,12 @@ declare class AuthModuleService extends AuthModuleService_base {
94
94
  resetPassword(token: string, newPassword: string): Promise<void>;
95
95
  /** Verify a JWT and return its decoded payload. Throws if invalid or expired. */
96
96
  verifyToken(token: string, secret: string): JwtPayload;
97
+ /**
98
+ * Issue a fresh JWT for a user by reading their current state from the DB.
99
+ * Uses `retrieveUserFresh` to bypass the identity map cache.
100
+ * Useful after updating a user's role or app_role_id outside the auth flow.
101
+ */
102
+ issueToken(userId: string): Promise<AuthResult>;
97
103
  /** Resolve permissions for a given app_role_id — gracefully degrades if module not loaded. */
98
104
  private resolvePermissions;
99
105
  private signToken;
package/dist/index.d.ts CHANGED
@@ -94,6 +94,12 @@ declare class AuthModuleService extends AuthModuleService_base {
94
94
  resetPassword(token: string, newPassword: string): Promise<void>;
95
95
  /** Verify a JWT and return its decoded payload. Throws if invalid or expired. */
96
96
  verifyToken(token: string, secret: string): JwtPayload;
97
+ /**
98
+ * Issue a fresh JWT for a user by reading their current state from the DB.
99
+ * Uses `retrieveUserFresh` to bypass the identity map cache.
100
+ * Useful after updating a user's role or app_role_id outside the auth flow.
101
+ */
102
+ issueToken(userId: string): Promise<AuthResult>;
97
103
  /** Resolve permissions for a given app_role_id — gracefully degrades if module not loaded. */
98
104
  private resolvePermissions;
99
105
  private signToken;
package/dist/index.js CHANGED
@@ -49,7 +49,6 @@ var import_crypto = require("crypto");
49
49
  var BCRYPT_ROUNDS = 12;
50
50
  var JWT_EXPIRES_IN = "7d";
51
51
  var JWT_EXPIRES_MS = 7 * 24 * 60 * 60 * 1e3;
52
- var RESET_TOKEN_EXPIRES_MS = 30 * 60 * 1e3;
53
52
  var AuthModuleService = class extends (0, import_framework_utils.MeridianService)({}) {
54
53
  container;
55
54
  constructor(container) {
@@ -299,6 +298,32 @@ var AuthModuleService = class extends (0, import_framework_utils.MeridianService
299
298
  verifyToken(token, secret) {
300
299
  return import_jsonwebtoken.default.verify(token, secret, { algorithms: ["HS256"] });
301
300
  }
301
+ /**
302
+ * Issue a fresh JWT for a user by reading their current state from the DB.
303
+ * Uses `retrieveUserFresh` to bypass the identity map cache.
304
+ * Useful after updating a user's role or app_role_id outside the auth flow.
305
+ */
306
+ async issueToken(userId) {
307
+ const userService = this.container.resolve("userModuleService");
308
+ const config = this.container.resolve("config");
309
+ const user = await userService.retrieveUserFresh(userId);
310
+ if (!user) {
311
+ throw Object.assign(new Error("User not found"), { status: 404 });
312
+ }
313
+ const permissions = await this.resolvePermissions(user.app_role_id);
314
+ const { token, jti, expiresAt } = this.signToken(user.id, null, [user.role ?? "member"], permissions, config.projectConfig.jwtSecret);
315
+ await userService.createSession(jti, user.id, expiresAt).catch(() => {
316
+ });
317
+ return {
318
+ user: {
319
+ id: user.id,
320
+ email: user.email,
321
+ first_name: user.first_name ?? null,
322
+ last_name: user.last_name ?? null
323
+ },
324
+ token
325
+ };
326
+ }
302
327
  /** Resolve permissions for a given app_role_id — gracefully degrades if module not loaded. */
303
328
  async resolvePermissions(appRoleId) {
304
329
  if (!appRoleId) return [];
package/dist/index.mjs CHANGED
@@ -9,7 +9,6 @@ import { randomBytes, randomUUID } from "crypto";
9
9
  var BCRYPT_ROUNDS = 12;
10
10
  var JWT_EXPIRES_IN = "7d";
11
11
  var JWT_EXPIRES_MS = 7 * 24 * 60 * 60 * 1e3;
12
- var RESET_TOKEN_EXPIRES_MS = 30 * 60 * 1e3;
13
12
  var AuthModuleService = class extends MeridianService({}) {
14
13
  container;
15
14
  constructor(container) {
@@ -259,6 +258,32 @@ var AuthModuleService = class extends MeridianService({}) {
259
258
  verifyToken(token, secret) {
260
259
  return jwt.verify(token, secret, { algorithms: ["HS256"] });
261
260
  }
261
+ /**
262
+ * Issue a fresh JWT for a user by reading their current state from the DB.
263
+ * Uses `retrieveUserFresh` to bypass the identity map cache.
264
+ * Useful after updating a user's role or app_role_id outside the auth flow.
265
+ */
266
+ async issueToken(userId) {
267
+ const userService = this.container.resolve("userModuleService");
268
+ const config = this.container.resolve("config");
269
+ const user = await userService.retrieveUserFresh(userId);
270
+ if (!user) {
271
+ throw Object.assign(new Error("User not found"), { status: 404 });
272
+ }
273
+ const permissions = await this.resolvePermissions(user.app_role_id);
274
+ const { token, jti, expiresAt } = this.signToken(user.id, null, [user.role ?? "member"], permissions, config.projectConfig.jwtSecret);
275
+ await userService.createSession(jti, user.id, expiresAt).catch(() => {
276
+ });
277
+ return {
278
+ user: {
279
+ id: user.id,
280
+ email: user.email,
281
+ first_name: user.first_name ?? null,
282
+ last_name: user.last_name ?? null
283
+ },
284
+ token
285
+ };
286
+ }
262
287
  /** Resolve permissions for a given app_role_id — gracefully degrades if module not loaded. */
263
288
  async resolvePermissions(appRoleId) {
264
289
  if (!appRoleId) return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meridianjs/auth",
3
- "version": "1.31.0",
3
+ "version": "2.1.0",
4
4
  "description": "Meridian auth module — JWT authentication and middleware",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -26,8 +26,8 @@
26
26
  "prepublishOnly": "npm run build"
27
27
  },
28
28
  "dependencies": {
29
- "@meridianjs/types": "^1.31.0",
30
- "@meridianjs/framework-utils": "^1.31.0",
29
+ "@meridianjs/types": "^2.1.0",
30
+ "@meridianjs/framework-utils": "^2.1.0",
31
31
  "jsonwebtoken": "^9.0.2",
32
32
  "bcrypt": "^5.1.1"
33
33
  },