@sanvika/auth 2.5.8 → 2.5.9

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.
Files changed (2) hide show
  1. package/dist/server.js +14 -2
  2. package/package.json +1 -1
package/dist/server.js CHANGED
@@ -302,6 +302,17 @@ async function authenticateAdmin(request) {
302
302
  return _buildUnauthorized("Invalid or expired token.", "INVALID_TOKEN");
303
303
  }
304
304
  const uid = saPayload.sub;
305
+ const jwtRole = saPayload.role;
306
+ if (jwtRole === "superadmin" && uid) {
307
+ const adminData2 = {
308
+ uid,
309
+ adminId: null,
310
+ role: "superadmin",
311
+ mobile: saPayload.mobile || null
312
+ };
313
+ _adminCache.set(cacheKey, { adminData: adminData2, expires: Date.now() + _ADMIN_CACHE_TTL });
314
+ return { success: true, admin: adminData2 };
315
+ }
305
316
  const admin = await verifyAdminFromAuth(uid);
306
317
  if (!admin) {
307
318
  return _buildUnauthorized("Unauthorized or admin account not found.", "ADMIN_NOT_FOUND");
@@ -309,13 +320,14 @@ async function authenticateAdmin(request) {
309
320
  if (admin.isBlocked) {
310
321
  return _buildForbidden("Admin account is blocked.", "ADMIN_BLOCKED");
311
322
  }
312
- if (!["admin", "superadmin", "moderator"].includes(admin.role)) {
323
+ const effectiveRole = admin.role || (jwtRole && ["admin", "superadmin", "moderator"].includes(jwtRole) ? jwtRole : null);
324
+ if (!effectiveRole || !["admin", "superadmin", "moderator"].includes(effectiveRole)) {
313
325
  return _buildForbidden("Invalid admin role.", "INVALID_ADMIN_ROLE");
314
326
  }
315
327
  const adminData = {
316
328
  uid: admin.uid,
317
329
  adminId: admin.adminId,
318
- role: admin.role,
330
+ role: effectiveRole,
319
331
  mobile: admin.mobile
320
332
  };
321
333
  _adminCache.set(cacheKey, { adminData, expires: Date.now() + _ADMIN_CACHE_TTL });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanvika/auth",
3
- "version": "2.5.8",
3
+ "version": "2.5.9",
4
4
  "description": "Sanvika Auth SDK — React components/hooks + server-side token verification and user proxy",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",