@tomei/sso 0.9.2 → 0.11.3

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.9.2",
3
+ "version": "0.11.3",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -101,6 +101,10 @@ export class LoginUser extends LoginUserBase {
101
101
  ],
102
102
  });
103
103
 
104
+ if (!user) {
105
+ throw new Error('Invalid credentials.');
106
+ }
107
+
104
108
  if (user) {
105
109
  const userInfo: IUserInfo = {
106
110
  ObjectId: user.id.toString(),
@@ -221,15 +225,13 @@ export class LoginUser extends LoginUserBase {
221
225
 
222
226
  // record new login history
223
227
  await LoginUser._LoginHistoryRepository.create({
224
- data: {
225
- userId: this.ObjectId,
226
- systemId: system.id,
227
- originIp: ipAddress,
228
- createdAt: new Date(),
229
- },
228
+ UserId: this.ObjectId,
229
+ SystemId: system.id,
230
+ OriginIp: ipAddress,
231
+ CreatedAt: new Date(),
230
232
  });
231
233
 
232
- return sessionId;
234
+ return `${this.ObjectId}:${sessionId}`;
233
235
  } catch (error) {
234
236
  throw error;
235
237
  }
@@ -263,8 +265,8 @@ export class LoginUser extends LoginUserBase {
263
265
  try {
264
266
  const userLogins = await LoginUser._LoginHistoryRepository.findAll({
265
267
  where: {
266
- userId: userId,
267
- systemId: systemId,
268
+ UserId: userId,
269
+ SystemId: systemId,
268
270
  },
269
271
  });
270
272
 
@@ -4,23 +4,27 @@ export class RedisService {
4
4
 
5
5
  private constructor() {}
6
6
 
7
- static async init(): Promise<RedisService> {
8
- if (!RedisService.client) {
9
- // Create a new Redis client
10
- RedisService.client = createClient({
11
- url: process.env.REDIS_URL,
12
- password: process.env.REDIS_PASSWORD,
13
- });
7
+ static async init(client?: any): Promise<RedisService> {
8
+ if (!client) {
9
+ if (!RedisService.client) {
10
+ // Create a new Redis client
11
+ RedisService.client = createClient({
12
+ url: process.env.REDIS_URL,
13
+ password: process.env.REDIS_PASSWORD,
14
+ });
14
15
 
15
- RedisService.client.on('error', (error) => {
16
- console.error('Redis error:', error);
17
- });
18
- RedisService.client.on('connect', () => console.log('Redis connected'));
19
- RedisService.client.on('reconnecting', () =>
20
- console.log('Redis reconnecting'),
21
- );
16
+ RedisService.client.on('error', (error) => {
17
+ console.error('Redis error:', error);
18
+ });
19
+ RedisService.client.on('connect', () => console.log('Redis connected'));
20
+ RedisService.client.on('reconnecting', () =>
21
+ console.log('Redis reconnecting'),
22
+ );
22
23
 
23
- await RedisService.client.connect();
24
+ await RedisService.client.connect();
25
+ }
26
+ } else {
27
+ RedisService.client = client;
24
28
  }
25
29
  return new RedisService();
26
30
  }
@@ -7,9 +7,9 @@ export class SessionService implements ISessionService {
7
7
 
8
8
  private constructor() {}
9
9
 
10
- static async init(): Promise<SessionService> {
10
+ static async init(redisClient?: any): Promise<SessionService> {
11
11
  const sessionService = new SessionService();
12
- SessionService._RedisService = await RedisService.init();
12
+ SessionService._RedisService = await RedisService.init(redisClient);
13
13
  return sessionService;
14
14
  }
15
15