next-session
Advanced tools
Comparing version 3.4.0 to 3.4.1
@@ -7,4 +7,4 @@ "use strict"; | ||
exports.promisifyStore = exports.expressSession = void 0; | ||
const events_1 = require("events"); | ||
const util_1 = require("util"); | ||
const events_1 = require("events"); | ||
const memory_1 = __importDefault(require("./store/memory")); | ||
@@ -11,0 +11,0 @@ function CompatibleStore() { |
@@ -0,3 +1,3 @@ | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
import { Options } from './types'; | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
export default function session(opts?: Options): (req: IncomingMessage, res: ServerResponse, next: (err?: any) => void) => void; |
/// <reference types="node" /> | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
import { Session, Options } from './types'; | ||
import { Options, Session } from './types'; | ||
export declare function applySession<T = {}>(req: IncomingMessage & { | ||
session?: Session | null | undefined; | ||
}, res: ServerResponse, options?: Options): Promise<void>; |
@@ -43,3 +43,3 @@ "use strict"; | ||
function setupStore(store) { | ||
if ('__normalized' in store) | ||
if ('__get' in store) | ||
return store; | ||
@@ -84,3 +84,2 @@ const s = store; | ||
} | ||
s.__normalized = true; | ||
return s; | ||
@@ -176,10 +175,15 @@ } | ||
const oldEnd = res.end; | ||
res.end = async function resEndProxy(...args) { | ||
res.end = function resEndProxy(...args) { | ||
const onSuccess = () => oldEnd.apply(this, args); | ||
if (stringify(req.session) !== prevSessStr) { | ||
await save(store, req.session); | ||
save(store, req.session).finally(onSuccess); | ||
} | ||
else if (req.session && shouldTouch && store.__touch) { | ||
await store.__touch(req.session.id, prepareSession(req.session)); | ||
store | ||
.__touch(req.session.id, prepareSession(req.session)) | ||
.finally(onSuccess); | ||
} | ||
oldEnd.apply(this, args); | ||
else { | ||
onSuccess(); | ||
} | ||
}; | ||
@@ -186,0 +190,0 @@ } |
@@ -1,6 +0,6 @@ | ||
export { default as withSession } from './withSession'; | ||
export { expressSession, promisifyStore } from './compat'; | ||
export { default as session } from './connect'; | ||
export { applySession } from './core'; | ||
export { promisifyStore, expressSession } from './compat'; | ||
export { default as MemoryStore } from './store/memory'; | ||
export { SessionData, SessionCookieData, SessionStore } from './types'; | ||
export { SessionCookieData, SessionData, SessionStore } from './types'; | ||
export { default as withSession } from './withSession'; |
@@ -6,5 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SessionStore = exports.MemoryStore = exports.expressSession = exports.promisifyStore = exports.applySession = exports.session = exports.withSession = void 0; | ||
var withSession_1 = require("./withSession"); | ||
Object.defineProperty(exports, "withSession", { enumerable: true, get: function () { return __importDefault(withSession_1).default; } }); | ||
exports.withSession = exports.SessionStore = exports.MemoryStore = exports.applySession = exports.session = exports.promisifyStore = exports.expressSession = void 0; | ||
var compat_1 = require("./compat"); | ||
Object.defineProperty(exports, "expressSession", { enumerable: true, get: function () { return compat_1.expressSession; } }); | ||
Object.defineProperty(exports, "promisifyStore", { enumerable: true, get: function () { return compat_1.promisifyStore; } }); | ||
var connect_1 = require("./connect"); | ||
@@ -14,5 +15,2 @@ Object.defineProperty(exports, "session", { enumerable: true, get: function () { return __importDefault(connect_1).default; } }); | ||
Object.defineProperty(exports, "applySession", { enumerable: true, get: function () { return core_1.applySession; } }); | ||
var compat_1 = require("./compat"); | ||
Object.defineProperty(exports, "promisifyStore", { enumerable: true, get: function () { return compat_1.promisifyStore; } }); | ||
Object.defineProperty(exports, "expressSession", { enumerable: true, get: function () { return compat_1.expressSession; } }); | ||
var memory_1 = require("./store/memory"); | ||
@@ -22,1 +20,3 @@ Object.defineProperty(exports, "MemoryStore", { enumerable: true, get: function () { return __importDefault(memory_1).default; } }); | ||
Object.defineProperty(exports, "SessionStore", { enumerable: true, get: function () { return types_1.SessionStore; } }); | ||
var withSession_1 = require("./withSession"); | ||
Object.defineProperty(exports, "withSession", { enumerable: true, get: function () { return __importDefault(withSession_1).default; } }); |
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { SessionStore, SessionData } from '../types'; | ||
import { SessionData, SessionStore } from '../types'; | ||
export default class MemoryStore extends EventEmitter implements SessionStore { | ||
@@ -5,0 +5,0 @@ sessions: Record<string, string>; |
@@ -37,3 +37,2 @@ import { Store as ExpressStore } from 'express-session'; | ||
__touch(sid: string, sess: SessionData): Promise<void>; | ||
__normalized: true; | ||
} & (SessionStore | ExpressStore); | ||
@@ -40,0 +39,0 @@ export interface Options { |
@@ -1,3 +0,3 @@ | ||
import { NextPage, NextApiHandler } from 'next'; | ||
import { NextApiHandler, NextPage } from 'next'; | ||
import { Options } from './types'; | ||
export default function withSession<T = {}>(handler: NextApiHandler | NextPage, options?: Options): NextApiHandler | NextPage; |
{ | ||
"name": "next-session", | ||
"version": "3.4.0", | ||
"version": "3.4.1", | ||
"description": "Simple promise-based session middleware for Next.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -11,3 +11,3 @@ # next-session | ||
> For a more battle-tested solution, you should use [express-session](https://github.com/expressjs/session) with [next-connect](https://github.com/hoangvvo/next-connect) instead. | ||
> Project status: While there will be bug fixes, it is unlikely that `next-session` will receive features PR in the future. Consider using alternatives like [express-session](https://github.com/expressjs/session)+[next-connect](https://github.com/hoangvvo/next-connect) or [next-iron-session](https://github.com/vvo/next-iron-session) instead. | ||
@@ -55,2 +55,4 @@ ## Installation | ||
**Note:** If you intend to call `session()` in multiple places, consider doing it only once and exporting it for elsewhere to avoid exceeded listeners. | ||
```javascript | ||
@@ -60,4 +62,6 @@ import { session } from 'next-session'; | ||
const mySession = session({ ...options }); | ||
const handler = nextConnect() | ||
.use(session({ ...options })) | ||
.use(mySession) | ||
.all(() => { | ||
@@ -64,0 +68,0 @@ req.session.views = req.session.views ? req.session.views + 1 : 1; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
298
37409
18
443