-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07dea4a
commit 3c79c94
Showing
3 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
const env = require("../dotenv"); | ||
const is = require("../framework/lib/is"); | ||
|
||
module.exports = { | ||
name : env.SESSION_NAME, | ||
cookieDomain : env.SESSION_COOKIE_DOMAIN, | ||
cookiePath : env.SESSION_COOKIE_PATH, | ||
expiry : 1000 * 60 * Number(env.SESSION_EXPIRY), | ||
secret : env.SESSION_SECRET, | ||
sameSite : env.SESSION_SAME_SITE, | ||
name : env.SESSION_NAME, | ||
cookieDomain : env.SESSION_COOKIE_DOMAIN, | ||
cookiePath : env.SESSION_COOKIE_PATH, | ||
expiry : 1000 * 60 * (Number(env.SESSION_EXPIRY) || 15), | ||
secret : env.SESSION_SECRET, | ||
secure : is.falsy(env.SESSION_SECURE?.toLowerCase()) ? false : true, | ||
sameSite : env.SESSION_SAME_SITE, | ||
storageDriver : (env.SESSION_STORE_DRIVER || "memory").toLowerCase(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const session = require("express-session"); | ||
const { v4: uuidv4 } = require("uuid"); | ||
|
||
|
||
module.exports = function sessionMiddleware(config, store) { | ||
const sessConfig = config.get("session"); | ||
const sessionConfig = { | ||
name: sessConfig.name, | ||
|
||
/* | ||
* secret is needed to sign the cookie | ||
*/ | ||
secret: sessConfig.secret, | ||
|
||
/* | ||
* generate a session ID. | ||
*/ | ||
genid: () => uuidv4(), | ||
resave: false, | ||
|
||
/* | ||
* true initializes a session for every user, | ||
* false initializes a session for only authenticated users | ||
*/ | ||
saveUninitialized: false, | ||
|
||
/* | ||
* Force session identifier cookie (max-age) to be (re-)set on every response | ||
*/ | ||
rolling: true, | ||
|
||
/* | ||
* Specify session cookie configuration | ||
*/ | ||
cookie: { | ||
domain: sessConfig.cookieDomain, | ||
|
||
/* | ||
* prevent client side JS from reading the cookie | ||
*/ | ||
httpOnly: true, | ||
|
||
/* | ||
* session max age in miliseconds | ||
*/ | ||
maxAge: sessConfig.expiry, | ||
|
||
/* | ||
* The path for which the session cookie is valid | ||
*/ | ||
path: sessConfig.cookiePath, | ||
|
||
/* | ||
* possible values: 'none', 'strict', 'lax' | ||
*/ | ||
sameSite: sessConfig.sameSite, | ||
|
||
/* | ||
* if true, serve secure cookies (i.e., only transmit cookie over https) | ||
*/ | ||
secure: sessConfig.secure, | ||
} | ||
}; | ||
|
||
return session({ ...sessionConfig, store }); | ||
}; |