Gathering detailed insights and metrics for maranda-koa2-session-mysql
Gathering detailed insights and metrics for maranda-koa2-session-mysql
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
JavaScript (52.42%)
TypeScript (47.58%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
1 Stars
35 Commits
5 Branches
1 Contributors
Updated on Jun 25, 2019
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
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
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
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-06-30
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 MoreLast 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