@social-mail/social-mail-web-server 1.8.413 → 1.8.415
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 +13 -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 +13 -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,31 @@ 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) {
|
|
54
48
|
// delete key path...
|
|
55
49
|
if (user.keyPath) {
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
this.cache.delete(user.keyPath);
|
|
51
|
+
this.userIDCache.delete(user.userID.toString(36));
|
|
58
52
|
}
|
|
59
53
|
}
|
|
60
54
|
return super.setAuthCookie(user, authCookie);
|
|
@@ -98,17 +92,17 @@ export default class UserAuthorizationService extends AuthorizationService {
|
|
|
98
92
|
private async clearLogin(userID) {
|
|
99
93
|
try {
|
|
100
94
|
const userKey = userID.toString(36);
|
|
101
|
-
const keyPath = await this.
|
|
95
|
+
const keyPath = await this.userIDCache.getOrCreate(userKey, null, (c) => c);
|
|
102
96
|
if (keyPath) {
|
|
103
|
-
|
|
97
|
+
this.cache.delete(keyPath);
|
|
104
98
|
}
|
|
105
|
-
|
|
99
|
+
this.userIDCache.delete(userKey);
|
|
106
100
|
} catch (error) {
|
|
107
101
|
// ignore this error...
|
|
108
102
|
if (error?.message === "not found") {
|
|
109
103
|
return;
|
|
110
104
|
}
|
|
111
|
-
console.
|
|
105
|
+
console.warn(error);
|
|
112
106
|
}
|
|
113
107
|
}
|
|
114
108
|
|