@tomei/sso 0.58.10 → 0.58.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.58.10",
3
+ "version": "0.58.11",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@ import { UserRepository } from './user.repository';
8
8
  import { IUserAttr, IUserInfo } from './interfaces/user-info.interface';
9
9
  import Staff from '../../models/staff.entity';
10
10
  import UserModel from '../../models/user.entity';
11
- import { createHash, randomBytes } from 'crypto';
11
+ import { createHash, randomBytes, randomUUID } from 'crypto';
12
12
  import { UserGroupRepository } from '../user-group/user-group.repository';
13
13
  import GroupSystemAccessModel from '../../models/group-system-access.entity';
14
14
  import SystemModel from '../../models/system.entity';
@@ -317,4 +317,46 @@ export class LoginUser extends User implements ILoginUser {
317
317
  // Part 3: Map Result to System Object
318
318
  return output;
319
319
  }
320
+
321
+ async setSession(systemCode: string, sessionId: string, dbTransaction: any) {
322
+ // fetch user session if exists
323
+ const sessionName =
324
+ ApplicationConfig.getComponentConfigValue('sessionName');
325
+
326
+ if (!sessionName) {
327
+ throw new Error('Session name is not set in the configuration');
328
+ }
329
+
330
+ const userSession = await this._SessionService.retrieveUserSession(
331
+ this.ObjectId,
332
+ sessionName,
333
+ );
334
+ const systemLogin = userSession.systemLogins.find(
335
+ (system) => system.code === systemCode,
336
+ );
337
+
338
+ if (systemLogin) {
339
+ const privileges = await this.getPrivileges(systemCode, dbTransaction);
340
+ systemLogin.sessionId = sessionId;
341
+ systemLogin.privileges = privileges;
342
+ userSession.systemLogins.map((system) =>
343
+ system.code === systemCode ? systemLogin : system,
344
+ );
345
+ } else {
346
+ // if not, add new system login into the userSession
347
+ const newLogin = {
348
+ id: systemCode,
349
+ code: systemCode,
350
+ sessionId: sessionId,
351
+ privileges: await this.getPrivileges(systemCode, dbTransaction),
352
+ };
353
+ userSession.systemLogins.push(newLogin);
354
+ }
355
+ // then update userSession inside the redis storage with 1 day duration of time-to-live
356
+ this._SessionService.setUserSession(
357
+ this.ObjectId,
358
+ userSession,
359
+ sessionName,
360
+ );
361
+ }
320
362
  }