Gathering detailed insights and metrics for koa-session2-redis
Gathering detailed insights and metrics for koa-session2-redis
Gathering detailed insights and metrics for koa-session2-redis
Gathering detailed insights and metrics for koa-session2-redis
npm install koa-session2-redis
Typescript
Module System
Min. Node Version
Node Version
NPM Version
62.4
Supply Chain
95.6
Quality
70.1
Maintenance
50
Vulnerability
95.3
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2 Commits
1 Branches
2 Contributors
Updated on Aug 06, 2018
Latest Version
0.0.2
Package Id
koa-session2-redis@0.0.2
Unpacked Size
9.76 kB
Size
3.78 kB
File Count
6
NPM Version
6.0.0
Node Version
8.9.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Middleware for Koa2 to get/set session use with custom stores such as Redis or mongodb
Use native ES6(async/await) by Nodejs v7.6.0 +
Or you can use the old versions:
node v7.6 +
npm install koa-session2
1const Koa = require("koa"); 2const session = require("koa-session2"); 3 4const app = new Koa(); 5 6app.use(session({ 7 key: "SESSIONID", //default "koa:sess" 8}));
Store.js
1const Redis = require("ioredis"); 2const { Store } = require("koa-session2"); 3 4class RedisStore extends Store { 5 constructor() { 6 super(); 7 this.redis = new Redis(); 8 } 9 10 async get(sid, ctx) { 11 let data = await this.redis.get(`SESSION:${sid}`); 12 return JSON.parse(data); 13 } 14 15 async set(session, { sid = this.getID(24), maxAge = 1000000 } = {}, ctx) { 16 try { 17 // Use redis set EX to automatically drop expired sessions 18 await this.redis.set(`SESSION:${sid}`, JSON.stringify(session), 'EX', maxAge / 1000); 19 } catch (e) {} 20 return sid; 21 } 22 23 async destroy(sid, ctx) { 24 return await this.redis.del(`SESSION:${sid}`); 25 } 26} 27 28module.exports = RedisStore;
main.js
1const Koa = require("koa"); 2const session = require("koa-session2"); 3const Store = require("./Store.js"); 4 5const app = new Koa(); 6 7app.use(session({ 8 store: new Store() 9})); 10 11app.use(ctx => { 12 let user = ctx.session.user; 13 14 ctx.session.view = "index"; 15});
Most options based on cookies
key
: a string for store session id in cookie
store
: a class for custom store (extend {Store}, func: #get(sid), #set(session, opts), #destory(sid))
maxAge
: a number representing the milliseconds from Date.now()
for expiry
expires
: a Date
object indicating the cookie's expiration date (expires at the end of session by default).
path
: a string indicating the path of the cookie (/
by default).
domain
: a string indicating the domain of the cookie (no default).
secure
: a boolean indicating whether the cookie is only to be sent over HTTPS (false
by default for HTTP, true
by default for HTTPS).
httpOnly
: a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (true
by default).
signed
: a boolean indicating whether the cookie is to be signed (false
by default). If this is true, another cookie of the same name with the .sig
suffix appended will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of cookie-name=cookie-value against the first Keygrip key. This signature key is used to detect tampering the next time a cookie is received.
overwrite
: a boolean indicating whether to overwrite previously set cookies of the same name (false
by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/2 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More