@adonisjs/session 6.2.1 → 6.3.0
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.
|
@@ -231,7 +231,7 @@ declare module '@ioc:Adonis/Addons/Session' {
|
|
|
231
231
|
/**
|
|
232
232
|
* Load session data from the driver
|
|
233
233
|
*/
|
|
234
|
-
load(): Promise<{
|
|
234
|
+
load(cookies: Record<string, any>): Promise<{
|
|
235
235
|
session: Record<string, any>;
|
|
236
236
|
flashMessages: Record<string, any> | null;
|
|
237
237
|
}>;
|
|
@@ -90,36 +90,42 @@ function defineTestsBindings(ApiRequest, ApiResponse, ApiClient, SessionManager)
|
|
|
90
90
|
this.assert.notProperty(this.flashMessages(), name);
|
|
91
91
|
});
|
|
92
92
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
93
|
+
* Adding hooks directly on the request object moves the hooks to
|
|
94
|
+
* the end of the queue (basically after the globally hooks)
|
|
95
95
|
*/
|
|
96
|
-
ApiClient.
|
|
96
|
+
ApiClient.onRequest((req) => {
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
98
|
+
* Hook into request and persist session data to be available
|
|
99
|
+
* on the server during the request.
|
|
100
100
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
req.setup(async (request) => {
|
|
102
|
+
/**
|
|
103
|
+
* Persist session data and set the session id within the
|
|
104
|
+
* cookie
|
|
105
|
+
*/
|
|
106
|
+
const { cookieName, sessionId } = await request.sessionClient.commit();
|
|
107
|
+
request.cookie(cookieName, sessionId);
|
|
108
|
+
/**
|
|
109
|
+
* Cleanup if request has error. Otherwise the teardown
|
|
110
|
+
* hook will clear
|
|
111
|
+
*/
|
|
112
|
+
return async (error) => {
|
|
113
|
+
if (error) {
|
|
114
|
+
await request.sessionClient.forget();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
});
|
|
103
118
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
119
|
+
* Load messages from the session store and keep a reference to it
|
|
120
|
+
* inside the response object.
|
|
121
|
+
*
|
|
122
|
+
* We also destroy the session after getting a copy of the session
|
|
123
|
+
* data
|
|
106
124
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
112
|
-
});
|
|
113
|
-
/**
|
|
114
|
-
* Load messages from the session store and keep a reference to it
|
|
115
|
-
* inside the response object.
|
|
116
|
-
*
|
|
117
|
-
* We also destroy the session after getting a copy of the session
|
|
118
|
-
* data
|
|
119
|
-
*/
|
|
120
|
-
ApiClient.teardown(async (response) => {
|
|
121
|
-
response.sessionJar = await response.request.sessionClient.load();
|
|
122
|
-
await response.request.sessionClient.forget();
|
|
125
|
+
req.teardown(async (response) => {
|
|
126
|
+
response.sessionJar = await response.request.sessionClient.load(response.cookies());
|
|
127
|
+
await response.request.sessionClient.forget();
|
|
128
|
+
});
|
|
123
129
|
});
|
|
124
130
|
}
|
|
125
131
|
exports.defineTestsBindings = defineTestsBindings;
|
|
@@ -45,8 +45,10 @@ class SessionClient extends Store_1.Store {
|
|
|
45
45
|
/**
|
|
46
46
|
* Load session from the driver
|
|
47
47
|
*/
|
|
48
|
-
async load() {
|
|
49
|
-
const
|
|
48
|
+
async load(cookies) {
|
|
49
|
+
const sessionIdCookie = cookies[this.config.cookieName];
|
|
50
|
+
const sessionId = sessionIdCookie ? sessionIdCookie.value : this.sessionId;
|
|
51
|
+
const contents = await this.driver.read(sessionId);
|
|
50
52
|
const store = new Store_1.Store(contents);
|
|
51
53
|
const flashMessages = store.pull(this.flashMessagesKey, null);
|
|
52
54
|
return {
|
|
@@ -34,6 +34,11 @@ export declare class Session implements SessionContract {
|
|
|
34
34
|
* A copy of previously set flash messages
|
|
35
35
|
*/
|
|
36
36
|
flashMessages: Store;
|
|
37
|
+
/**
|
|
38
|
+
* Session id for the current request. It will be different
|
|
39
|
+
* from the "this.sessionId" when regenerate is called.
|
|
40
|
+
*/
|
|
41
|
+
private currentSessionId;
|
|
37
42
|
/**
|
|
38
43
|
* A instance of store with values read from the driver. The store
|
|
39
44
|
* in initiated inside the [[initiate]] method
|
|
@@ -43,7 +48,7 @@ export declare class Session implements SessionContract {
|
|
|
43
48
|
* Whether or not to re-generate the session id before comitting
|
|
44
49
|
* session values.
|
|
45
50
|
*/
|
|
46
|
-
private
|
|
51
|
+
private regeneratedSessionId;
|
|
47
52
|
/**
|
|
48
53
|
* A copy of flash messages. The `input` messages
|
|
49
54
|
* are overwritten when any of the input related
|
|
@@ -46,11 +46,16 @@ class Session {
|
|
|
46
46
|
* A copy of previously set flash messages
|
|
47
47
|
*/
|
|
48
48
|
this.flashMessages = new Store_1.Store({});
|
|
49
|
+
/**
|
|
50
|
+
* Session id for the current request. It will be different
|
|
51
|
+
* from the "this.sessionId" when regenerate is called.
|
|
52
|
+
*/
|
|
53
|
+
this.currentSessionId = this.sessionId;
|
|
49
54
|
/**
|
|
50
55
|
* Whether or not to re-generate the session id before comitting
|
|
51
56
|
* session values.
|
|
52
57
|
*/
|
|
53
|
-
this.
|
|
58
|
+
this.regeneratedSessionId = false;
|
|
54
59
|
/**
|
|
55
60
|
* A copy of flash messages. The `input` messages
|
|
56
61
|
* are overwritten when any of the input related
|
|
@@ -180,7 +185,8 @@ class Session {
|
|
|
180
185
|
*/
|
|
181
186
|
regenerate() {
|
|
182
187
|
this.ctx.logger.trace('explicitly re-generating session id');
|
|
183
|
-
this.
|
|
188
|
+
this.sessionId = (0, helpers_1.cuid)();
|
|
189
|
+
this.regeneratedSessionId = true;
|
|
184
190
|
}
|
|
185
191
|
/**
|
|
186
192
|
* Set/update session value
|
|
@@ -331,9 +337,8 @@ class Session {
|
|
|
331
337
|
/**
|
|
332
338
|
* Cleanup old session and re-generate new session
|
|
333
339
|
*/
|
|
334
|
-
if (this.
|
|
335
|
-
await this.driver.destroy(this.
|
|
336
|
-
this.sessionId = (0, helpers_1.cuid)();
|
|
340
|
+
if (this.regeneratedSessionId) {
|
|
341
|
+
await this.driver.destroy(this.currentSessionId);
|
|
337
342
|
}
|
|
338
343
|
/**
|
|
339
344
|
* Touch the session cookie to keep it alive.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/session",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "Session provider for AdonisJS",
|
|
5
5
|
"typings": "./build/adonis-typings/index.d.ts",
|
|
6
6
|
"main": "build/providers/SessionProvider.js",
|
|
@@ -12,40 +12,41 @@
|
|
|
12
12
|
"build/instructions.md"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@poppinss/utils": "^4.0.
|
|
16
|
-
"fs-extra": "^10.0
|
|
15
|
+
"@poppinss/utils": "^4.0.4",
|
|
16
|
+
"fs-extra": "^10.1.0"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"@adonisjs/core": "^5.5.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@adonisjs/core": "^5.
|
|
22
|
+
"@adonisjs/core": "^5.8.2",
|
|
23
23
|
"@adonisjs/mrm-preset": "^5.0.3",
|
|
24
24
|
"@adonisjs/redis": "^7.2.0",
|
|
25
25
|
"@adonisjs/require-ts": "^2.0.11",
|
|
26
26
|
"@japa/assert": "^1.3.4",
|
|
27
|
-
"@japa/preset-adonis": "^1.0.
|
|
27
|
+
"@japa/preset-adonis": "^1.0.15",
|
|
28
28
|
"@japa/run-failed-tests": "^1.0.7",
|
|
29
|
-
"@japa/runner": "^2.0.
|
|
29
|
+
"@japa/runner": "^2.0.8",
|
|
30
30
|
"@japa/spec-reporter": "^1.1.12",
|
|
31
31
|
"@poppinss/dev-utils": "^2.0.3",
|
|
32
|
-
"@types/node": "^17.0.
|
|
32
|
+
"@types/node": "^17.0.34",
|
|
33
33
|
"@types/supertest": "^2.0.12",
|
|
34
34
|
"commitizen": "^4.2.4",
|
|
35
35
|
"copyfiles": "^2.4.1",
|
|
36
36
|
"cz-conventional-changelog": "^3.3.0",
|
|
37
37
|
"del-cli": "^4.0.1",
|
|
38
|
-
"eslint": "^8.
|
|
38
|
+
"eslint": "^8.15.0",
|
|
39
39
|
"eslint-config-prettier": "^8.5.0",
|
|
40
40
|
"eslint-plugin-adonis": "^2.1.0",
|
|
41
41
|
"eslint-plugin-prettier": "^4.0.0",
|
|
42
42
|
"github-label-sync": "^2.2.0",
|
|
43
|
-
"husky": "^
|
|
43
|
+
"husky": "^8.0.1",
|
|
44
44
|
"mrm": "^4.0.0",
|
|
45
45
|
"np": "^7.6.1",
|
|
46
46
|
"prettier": "^2.6.2",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"set-cookie-parser": "^2.4.8",
|
|
48
|
+
"supertest": "^6.2.3",
|
|
49
|
+
"typescript": "^4.6.4"
|
|
49
50
|
},
|
|
50
51
|
"scripts": {
|
|
51
52
|
"mrm": "mrm --preset=@adonisjs/mrm-preset",
|