@meridianjs/auth 1.31.0 → 2.0.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
@@ -299,6 +299,32 @@ var AuthModuleService = class extends (0, import_framework_utils.MeridianService
299
299
  verifyToken(token, secret) {
300
300
  return import_jsonwebtoken.default.verify(token, secret, { algorithms: ["HS256"] });
301
301
  }
302
+ /**
303
+ * Issue a fresh JWT for a user by reading their current state from the DB.
304
+ * Uses `retrieveUserFresh` to bypass the identity map cache.
305
+ * Useful after updating a user's role or app_role_id outside the auth flow.
306
+ */
307
+ async issueToken(userId) {
308
+ const userService = this.container.resolve("userModuleService");
309
+ const config = this.container.resolve("config");
310
+ const user = await userService.retrieveUserFresh(userId);
311
+ if (!user) {
312
+ throw Object.assign(new Error("User not found"), { status: 404 });
313
+ }
314
+ const permissions = await this.resolvePermissions(user.app_role_id);
315
+ const { token, jti, expiresAt } = this.signToken(user.id, null, [user.role ?? "member"], permissions, config.projectConfig.jwtSecret);
316
+ await userService.createSession(jti, user.id, expiresAt).catch(() => {
317
+ });
318
+ return {
319
+ user: {
320
+ id: user.id,
321
+ email: user.email,
322
+ first_name: user.first_name ?? null,
323
+ last_name: user.last_name ?? null
324
+ },
325
+ token
326
+ };
327
+ }
302
328
  /** Resolve permissions for a given app_role_id — gracefully degrades if module not loaded. */
303
329
  async resolvePermissions(appRoleId) {
304
330
  if (!appRoleId) return [];
package/dist/index.mjs CHANGED
@@ -259,6 +259,32 @@ var AuthModuleService = class extends MeridianService({}) {
259
259
  verifyToken(token, secret) {
260
260
  return jwt.verify(token, secret, { algorithms: ["HS256"] });
261
261
  }
262
+ /**
263
+ * Issue a fresh JWT for a user by reading their current state from the DB.
264
+ * Uses `retrieveUserFresh` to bypass the identity map cache.
265
+ * Useful after updating a user's role or app_role_id outside the auth flow.
266
+ */
267
+ async issueToken(userId) {
268
+ const userService = this.container.resolve("userModuleService");
269
+ const config = this.container.resolve("config");
270
+ const user = await userService.retrieveUserFresh(userId);
271
+ if (!user) {
272
+ throw Object.assign(new Error("User not found"), { status: 404 });
273
+ }
274
+ const permissions = await this.resolvePermissions(user.app_role_id);
275
+ const { token, jti, expiresAt } = this.signToken(user.id, null, [user.role ?? "member"], permissions, config.projectConfig.jwtSecret);
276
+ await userService.createSession(jti, user.id, expiresAt).catch(() => {
277
+ });
278
+ return {
279
+ user: {
280
+ id: user.id,
281
+ email: user.email,
282
+ first_name: user.first_name ?? null,
283
+ last_name: user.last_name ?? null
284
+ },
285
+ token
286
+ };
287
+ }
262
288
  /** Resolve permissions for a given app_role_id — gracefully degrades if module not loaded. */
263
289
  async resolvePermissions(appRoleId) {
264
290
  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.0.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.0.0",
30
+ "@meridianjs/framework-utils": "^2.0.0",
31
31
  "jsonwebtoken": "^9.0.2",
32
32
  "bcrypt": "^5.1.1"
33
33
  },