Gathering detailed insights and metrics for maranda-koa2-session-mysql
Gathering detailed insights and metrics for maranda-koa2-session-mysql
npm install maranda-koa2-session-mysql
Typescript
Module System
Node Version
NPM Version
56.1
Supply Chain
85.8
Quality
75
Maintenance
25
Vulnerability
99.6
License
JavaScript (52.42%)
TypeScript (47.58%)
Total Downloads
4,141
Last Day
4
Last Week
16
Last Month
43
Last Year
332
1 Stars
35 Commits
5 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
3.1.9
Package Id
maranda-koa2-session-mysql@3.1.9
Unpacked Size
20.21 kB
Size
6.30 kB
File Count
7
NPM Version
6.9.0
Node Version
12.4.0
Cumulative downloads
Total Downloads
Last day
0%
4
Compared to previous day
Last week
1,500%
16
Compared to previous week
Last month
65.4%
43
Compared to previous month
Last year
-29.1%
332
Compared to previous year
4
app.ts
1import Session, { Sequelize } from 'maranda-koa2-session-mysql' 2 3import Koa from 'koa'; 4 5interface SessionData extends Session.DataType{ 6 name:string, 7 id: number, 8 stauts:boolean, 9 friend: sessionData, 10 group: [number,string,sessionData] 11} 12export interface Ctx extends Session.Ctx<SessionData> { 13 //if have other context 14} 15const app = new Koa<any, Ctx>(); 16const sequelize = new Sequelize('xxx', 'xxx', 'xxx', { 17 dialect: 'mysql', 18 host: 'localhost', 19 port: 3306, 20}) 21//you can set the gc probability whith molecula and denominato(this example 5/1000, default 1/100), tableName(custom tablename, default sessions), gcType('auto' or 'manul', if you set it to 'manul, you may do the session gc work by your self), ... 22//you mast ensure that there is not table named 'sessions' or your custom tablename in your database_schema 23app.use(Session.middware( 24 sequelize, 25 { 26 gcOpts: { probDenominator: 100, probMolecular: 1, type: 'auto' }, 27 defaultExpiry: 24 * 60 * 60 * 1000 //if the client close without set the session expiry, the some client will not create session again in 1 day, 28 } 29)); 30app.use((ctx, next) => { 31 if (ctx.path == '/'){ 32 if (ctx.session.isNewRecord) { // if true means that there is no session or the session has been expired of the request 33 ctx.body = `please login` 34 }else{ 35 ... 36 } 37 } 38}); 39app.use((ctx, next) => { 40 if(ctx.path == '/login'){ 41 const userCode = 'ss', 42 passWord = 'sss', 43 expiry = 5*24*60*60*1000; //5 days 44 .... 45 ctx.session.data.friend.id = 'xxx'; 46 ctx.session.data.id = code; 47 ctx.session.expiryTo = new Date(Date.now()+expiry); 48 //or you can set expiry as : 49 ctx.session.expiry = expiry; //means ctx.session.expiryTo = new Date(ctx.session.createAt.getTime() + expiry) 50 // if you do not set expiry or the expiryTo, we set cookie by defult, means when you close the window, the session cookie will be deleted 51 // if you do save session data manully, like 'ctx.session.save()', you must set the cookies by your self, like 'ctx.cookie.set(...)' 52 await next(); 53 //do not set your session data after next, because it will never work only if you do save session data munully, like 'ctx.session.save()', and then set the cookies by your self 54 .... 55 } 56}); 57app.use((ctx, next) => { 58 if (ctx.path == '/logout' && !ctx.session.isNewRecord) { 59 await ctx.session.destroy(); 60 } 61}); 62 63app.listen(80);
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
21 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
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