@social-mail/social-mail-web-server 1.8.414 → 1.8.416
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/server/services/UserAuthorizationService.d.ts +3 -2
- package/dist/server/services/UserAuthorizationService.d.ts.map +1 -1
- package/dist/server/services/UserAuthorizationService.js +17 -19
- package/dist/server/services/UserAuthorizationService.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/server/services/UserAuthorizationService.ts +17 -19
package/package.json
CHANGED
|
@@ -3,20 +3,15 @@ import AuthorizationService, { ICookie } from "@entity-access/server-pages/dist/
|
|
|
3
3
|
import SocialMailContext from "../model/SocialMailContext.js";
|
|
4
4
|
import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
|
|
5
5
|
import { SessionUser } from "@entity-access/server-pages/dist/core/SessionUser.js";
|
|
6
|
-
import BaseDiskCache from "../../common/BaseDiskCache.js";
|
|
7
|
-
import { join } from "path";
|
|
8
|
-
import { globalEnv } from "../../common/globalEnv.js";
|
|
9
6
|
import { IAuthorizationCookie } from "@entity-access/server-pages/dist/services/IAuthorizationCookie.js";
|
|
10
7
|
import MessagingService from "./message-events/MessagingService.js";
|
|
8
|
+
import TimedCache from "@entity-access/entity-access/dist/common/cache/TimedCache.js";
|
|
11
9
|
|
|
12
10
|
@RegisterSingleton
|
|
13
11
|
export default class UserAuthorizationService extends AuthorizationService {
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
keepTTLSeconds: 60*60*1000,
|
|
18
|
-
maxAge: 24*60*60*1000
|
|
19
|
-
});
|
|
13
|
+
cache = new TimedCache(60000,90000);
|
|
14
|
+
userIDCache = new TimedCache(90000, 180000);
|
|
20
15
|
|
|
21
16
|
@Inject
|
|
22
17
|
ms: MessagingService;
|
|
@@ -29,32 +24,35 @@ export default class UserAuthorizationService extends AuthorizationService {
|
|
|
29
24
|
}
|
|
30
25
|
|
|
31
26
|
async loadUserSessionFromCookie(cookie: string, user: SessionUser) {
|
|
32
|
-
const
|
|
33
|
-
const info = await this.diskCache.getOrCreateJsonAsync(keyPath, async () => {
|
|
27
|
+
const info = await this.cache.getOrCreateAsync(cookie, async () => {
|
|
34
28
|
const sessionID = await this.decode(cookie);
|
|
35
29
|
return await this.loadSessionFromDb(sessionID);
|
|
36
30
|
});
|
|
37
31
|
user.sessionID = info.sessionID;
|
|
38
32
|
if (!info.userID) {
|
|
39
33
|
// delete cache. cache is invalid...
|
|
40
|
-
|
|
34
|
+
this.cache.delete(cookie);
|
|
41
35
|
return;
|
|
42
36
|
}
|
|
43
37
|
user.userID = info.userID;
|
|
44
38
|
user.roles = info.roles;
|
|
45
39
|
user.expiry = info.expiry;
|
|
46
|
-
user.keyPath =
|
|
40
|
+
user.keyPath = cookie;
|
|
47
41
|
user.fileAccessList = info.fileAccessList;
|
|
48
42
|
(user as any).isAuthorized = true;
|
|
49
|
-
|
|
43
|
+
this.userIDCache.getOrCreate(user.userID.toString(36), cookie, (c) => c);
|
|
50
44
|
}
|
|
51
45
|
|
|
52
46
|
async setAuthCookie(user: SessionUser, authCookie: IAuthorizationCookie): Promise<ICookie> {
|
|
53
47
|
if (authCookie === null) {
|
|
48
|
+
const { userID } = user;
|
|
49
|
+
if (userID) {
|
|
50
|
+
this.ms.removeUserLoginSessions.notify({ userID });
|
|
51
|
+
}
|
|
54
52
|
// delete key path...
|
|
55
53
|
if (user.keyPath) {
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
this.cache.delete(user.keyPath);
|
|
55
|
+
this.userIDCache.delete(user.userID.toString(36));
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
return super.setAuthCookie(user, authCookie);
|
|
@@ -98,17 +96,17 @@ export default class UserAuthorizationService extends AuthorizationService {
|
|
|
98
96
|
private async clearLogin(userID) {
|
|
99
97
|
try {
|
|
100
98
|
const userKey = userID.toString(36);
|
|
101
|
-
const keyPath = await this.
|
|
99
|
+
const keyPath = await this.userIDCache.getOrCreate(userKey, null, (c) => c);
|
|
102
100
|
if (keyPath) {
|
|
103
|
-
|
|
101
|
+
this.cache.delete(keyPath);
|
|
104
102
|
}
|
|
105
|
-
|
|
103
|
+
this.userIDCache.delete(userKey);
|
|
106
104
|
} catch (error) {
|
|
107
105
|
// ignore this error...
|
|
108
106
|
if (error?.message === "not found") {
|
|
109
107
|
return;
|
|
110
108
|
}
|
|
111
|
-
console.
|
|
109
|
+
console.warn(error);
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
112
|
|