Fixed BadgeIDs not in user's token anymore
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -114,7 +114,7 @@ export default class Authorizations {
return requestedSites.filter((site) => sites.has(site));
}
- public static async buildUserToken(tenantID: string, user: User): Promise<UserToken> {
+ public static async buildUserToken(tenantID: string, user: User, tags: Tag[]): Promise<UserToken> {
const companyIDs = new Set<string>();
const siteIDs = [];
const siteAdminIDs = [];
@@ -155,7 +155,7 @@ export default class Authorizations {
'name': user.name,
'mobile': user.mobile,
'email': user.email,
- 'tagIDs': user.tags ? user.tags.filter((tag) => tag.active).map((tag) => tag.id) : [],
+ 'tagIDs': tags ? tags.filter((tag) => tag.active).map((tag) => tag.id) : [],
'firstName': user.firstName,
'locale': user.locale,
'language': Utils.getLanguageFromLocale(user.locale),
@@ -797,7 +797,7 @@ export default class Authorizations {
// Check Auth if local user
if (user.issuer && authAction) {
// Build the JWT Token
- const userToken = await Authorizations.buildUserToken(tenantID, user);
+ const userToken = await Authorizations.buildUserToken(tenantID, user, [tag]);
// Authorized?
const context = {
user: transaction ? transaction.userID : null,

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -15,7 +15,6 @@ import I18nManager from '../../../../utils/I18nManager';
import Logging from '../../../../utils/Logging';
import NotificationHandler from '../../../../notification/NotificationHandler';
import { ServerAction } from '../../../../types/Server';
-import SessionHashService from './SessionHashService';
import SiteStorage from '../../../../storage/mongodb/SiteStorage';
import { StatusCodes } from 'http-status-codes';
import Tag from '../../../../types/Tag';
@@ -881,8 +880,10 @@ export default class AuthService {
// Reset wrong number of trial
await UserStorage.saveUserPassword(tenantID, user.id,
{ passwordWrongNbrTrials: 0, passwordBlockedUntil: null, passwordResetHash: null });
- // Yes: build payload
- const payload: UserToken = await Authorizations.buildUserToken(tenantID, user);
+ // Get the tags (limited) to avoid an overweighted token
+ const tags = await UserStorage.getTags(tenantID, { userIDs: [user.id] }, Constants.DB_PARAMS_DEFAULT_RECORD);
+ // Yes: build token
+ const payload: UserToken = await Authorizations.buildUserToken(tenantID, user, tags.result);
// Build token
let token: string;
// Role Demo?

MODIFY
src/utils/Constants.ts
src/utils/Constants.ts
@@ -19,6 +19,7 @@ export default class Constants {
public static readonly DB_PARAMS_MAX_LIMIT: DbParams = Object.freeze({ limit: Constants.DB_RECORD_COUNT_NO_LIMIT, skip: 0, sort: null });
public static readonly DB_PARAMS_SINGLE_RECORD: DbParams = Object.freeze({ limit: 1, skip: 0, sort: null });
+ public static readonly DB_PARAMS_DEFAULT_RECORD: DbParams = Object.freeze({ limit: Constants.DB_RECORD_COUNT_DEFAULT, skip: 0, sort: null });
public static readonly DB_PARAMS_COUNT_ONLY: DbParams = Object.freeze({ limit: Constants.DB_RECORD_COUNT_NO_LIMIT, skip: 0, onlyRecordCount: true, sort: null });
public static readonly EXPORT_PAGE_SIZE = 1000;

Fixed BadgeIDs not in user's token anymore