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
Copy file name to clipboardExpand all lines: HISTORY.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,27 @@
2
2
3
3
### 🚀 Improvements
4
4
5
+
* Add dynamic cookie options support
6
+
7
+
Cookie options can now be dynamic, allowing for more flexible and context-aware configuration based on each request. This feature enables programmatic modification of cookie attributes like `secure`, `httpOnly`, `sameSite`, `maxAge`, `domain`, and `path` based on session or request conditions.
8
+
9
+
```js
10
+
var app =express()
11
+
app.use(session({
12
+
secret:'keyboard cat',
13
+
resave:false,
14
+
saveUninitialized:true,
15
+
cookie:function (req) {
16
+
var match =req.url.match(/^\/([^/]+)/);
17
+
return {
18
+
path: match ?'/'+ match[1] :'/',
19
+
httpOnly:true,
20
+
secure:req.secure||false,
21
+
maxAge:60000
22
+
}
23
+
}
24
+
}))
25
+
```
5
26
* Add sameSite 'auto' support for automatic SameSite attribute configuration
6
27
7
28
Added `sameSite: 'auto'` option for cookie configuration that automatically sets `SameSite=None`forHTTPS and `SameSite=Lax`forHTTP connections, simplifying cookie handling across different environments.
In addition to providing a static object, you can also pass a callback function to dynamically generate the cookie options for each request. The callback receives the `req` object as its argument and should return an object containing the cookie settings.
53
+
54
+
```js
55
+
var app =express()
56
+
app.use(session({
57
+
secret:'keyboard cat',
58
+
resave:false,
59
+
saveUninitialized:true,
60
+
cookie:function(req) {
61
+
var match =req.url.match(/^\/([^/]+)/);
62
+
return {
63
+
path: match ?'/'+ match[1] :'/',
64
+
httpOnly:true,
65
+
secure:req.secure||false,
66
+
maxAge:60000
67
+
}
68
+
}
69
+
}))
70
+
```
71
+
52
72
The following are options that can be set in this object.
0 commit comments