You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor, remove rolling option and fix unreliable tests (#283)
* Remove rolling option
* Fix test
* Update touch behavior
* Fix session date
* Add deprecated opts.rolling compat
* update depre rolling check
* Refactor
* Update README
* refactor
* Cleanup and type fixes
* type fixes
* Fix Jest
* Update test
* Explicit test for touch in callback store
* Fix touch
| name | The name of the cookie to be read from the request and set to the response. |`sid`|
179
179
| store | The session store instance to be used. |`MemoryStore`|
180
180
| genid | The function that generates a string for a new session ID. |[`nanoid`](https://github.com/ai/nanoid)|
181
-
| encode | Transforms session ID before setting cookie. It should return the encoded/encrypted session ID. | undefined |
182
-
| decode | Transforms session ID back while getting from cookie. It takes the raw session ID and returns the decoded/decrypted session ID. | undefined |
183
-
| touchAfter | Only touch (extend session lifetime despite no modification) after an amount of time to decrease database load. Setting the value to `-1` will disable `touch()`. |`0` (Touch every time) |
184
-
| rolling | Extends the life time of the cookie in the browser if the session is touched. This respects touchAfter. |`false`|
181
+
| encode | Transforms session ID before setting cookie. It takes the raw session ID and returns the decoded/decrypted session ID. | undefined |
182
+
| decode | Transforms session ID back while getting from cookie. It should return the encoded/encrypted session ID | undefined |
183
+
| touchAfter | Only touch after an amount of time. Disabled by default or if set to `-1`. See [touchAfter](#touchAfter). |`-1` (Disabled) |
185
184
| autoCommit | Automatically commit session. Disable this if you want to manually `session.commit()`|`true`|
186
185
| cookie.secure | Specifies the boolean value for the **Secure**`Set-Cookie` attribute. |`false`|
187
186
| cookie.httpOnly | Specifies the boolean value for the **httpOnly**`Set-Cookie` attribute. |`true`|
| cookie.sameSite | Specifies the value for the **SameSite**`Set-Cookie` attribute. | unset |
191
190
| cookie.maxAge |**(in seconds)** Specifies the value for the **Max-Age**`Set-Cookie` attribute. | unset (Browser session) |
192
191
192
+
### touchAfter
193
+
194
+
Touching refers to the extension of session lifetime, both in browser (by modifying `Expires` attribute in [Set-Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) header) and session store (using its respective method). This prevents the session from being expired after a while.
195
+
196
+
In `autoCommit` mode (which is enabled by default), for optimization, a session is only touched, not saved, if it is not modified. The value of `touchAfter` allows you to skip touching if the session is still recent, thus, decreasing database load.
197
+
193
198
### encode/decode
194
199
195
200
You may supply a custom pair of function that *encode/decode* or *encrypt/decrypt* the cookie on every request.
// compat: if rolling is `true`, user might have wanted to touch every time
119
+
// thus defaulting options.touchAfter to 0 instead of -1
120
+
if(options.rolling&&!('touchAfter'inoptions)){
121
+
console.warn(
122
+
'The use of options.rolling is deprecated. Setting this to `true` without options.touchAfter causes options.touchAfter to be defaulted to `0` (always)'
0 commit comments