iron-session 2.0.0-alpha.9 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +608 -55
- package/dist/index.d.ts +52 -17
- package/dist/index.js +137 -46
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +160 -0
- package/dist/index.mjs.map +7 -0
- package/express/dist/index.d.ts +6 -0
- package/express/dist/index.js +65 -0
- package/express/dist/index.js.map +7 -0
- package/express/dist/index.mjs +37 -0
- package/express/dist/index.mjs.map +7 -0
- package/express/index.d.ts +6 -0
- package/express/index.js +65 -0
- package/express/index.js.map +7 -0
- package/express/index.mjs +37 -0
- package/express/index.mjs.map +7 -0
- package/express/index.test.ts +41 -0
- package/express/index.ts +19 -0
- package/express/tsconfig.json +8 -0
- package/next/dist/index.d.ts +9 -13
- package/next/dist/index.js +60 -5
- package/next/dist/index.js.map +3 -3
- package/next/dist/index.mjs +45 -0
- package/next/dist/index.mjs.map +7 -0
- package/next/index.d.ts +11 -0
- package/next/{dist/index.cjs → index.js} +29 -3
- package/next/index.js.map +7 -0
- package/next/index.mjs +45 -0
- package/next/index.mjs.map +7 -0
- package/next/index.test.ts +184 -0
- package/next/index.ts +49 -0
- package/next/tsconfig.json +8 -0
- package/package.json +84 -49
- package/dist/index.cjs +0 -127
- package/dist/index.cjs.map +0 -7
- package/next/dist/index.cjs.map +0 -7
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// express/index.ts
|
|
2
|
+
import { getIronSession } from "iron-session";
|
|
3
|
+
|
|
4
|
+
// src/getPropertyDescriptorForReqSession.ts
|
|
5
|
+
function getPropertyDescriptorForReqSession(session) {
|
|
6
|
+
return {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get() {
|
|
9
|
+
return session;
|
|
10
|
+
},
|
|
11
|
+
set(value) {
|
|
12
|
+
const keys = Object.keys(value);
|
|
13
|
+
const currentKeys = Object.keys(session);
|
|
14
|
+
currentKeys.forEach((key) => {
|
|
15
|
+
if (!keys.includes(key)) {
|
|
16
|
+
delete session[key];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
keys.forEach((key) => {
|
|
20
|
+
session[key] = value[key];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// express/index.ts
|
|
27
|
+
function ironSession(sessionOptions) {
|
|
28
|
+
return async function ironSessionMiddleware(req, res, next) {
|
|
29
|
+
const session = await getIronSession(req, res, sessionOptions);
|
|
30
|
+
Object.defineProperty(req, "session", getPropertyDescriptorForReqSession(session));
|
|
31
|
+
next();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
ironSession
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../index.ts", "../../src/getPropertyDescriptorForReqSession.ts"],
|
|
4
|
+
"sourcesContent": ["import type { IronSessionOptions } from \"iron-session\";\nimport { getIronSession } from \"iron-session\";\nimport type { Request, Response, NextFunction } from \"express\";\nimport getPropertyDescriptorForReqSession from \"../src/getPropertyDescriptorForReqSession\";\n\nexport function ironSession(\n sessionOptions: IronSessionOptions,\n): (req: Request, res: Response, next: NextFunction) => Promise<void> {\n return async function ironSessionMiddleware(req, res, next) {\n const session = await getIronSession(req, res, sessionOptions);\n Object.defineProperty(\n req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n\n next();\n };\n}\n", "import type { IronSession } from \".\";\n\nexport default function getPropertyDescriptorForReqSession(\n session: IronSession,\n): PropertyDescriptor {\n return {\n enumerable: true,\n get() {\n return session;\n },\n set(value) {\n const keys = Object.keys(value);\n const currentKeys = Object.keys(session);\n\n currentKeys.forEach((key) => {\n if (!keys.includes(key)) {\n // @ts-ignore See comment in IronSessionData interface\n delete session[key];\n }\n });\n\n keys.forEach((key) => {\n // @ts-ignore See comment in IronSessionData interface\n session[key] = value[key];\n });\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";AACA;;;ACCe,4CACb,SACoB;AACpB,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,MAAM;AACJ,aAAO;AAAA;AAAA,IAET,IAAI,OAAO;AACT,YAAM,OAAO,OAAO,KAAK;AACzB,YAAM,cAAc,OAAO,KAAK;AAEhC,kBAAY,QAAQ,CAAC,QAAQ;AAC3B,YAAI,CAAC,KAAK,SAAS,MAAM;AAEvB,iBAAO,QAAQ;AAAA;AAAA;AAInB,WAAK,QAAQ,CAAC,QAAQ;AAEpB,gBAAQ,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;;;ADlBtB,qBACL,gBACoE;AACpE,SAAO,qCAAqC,KAAK,KAAK,MAAM;AAC1D,UAAM,UAAU,MAAM,eAAe,KAAK,KAAK;AAC/C,WAAO,eACL,KACA,WACA,mCAAmC;AAGrC;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IronSessionOptions } from 'iron-session';
|
|
2
|
+
import { Request, Response, NextFunction } from 'express';
|
|
3
|
+
|
|
4
|
+
declare function ironSession(sessionOptions: IronSessionOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
5
|
+
|
|
6
|
+
export { ironSession };
|
package/express/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
__markAsModule(target);
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, module2, desc) => {
|
|
14
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(module2))
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
17
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __toModule = (module2) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// express/index.ts
|
|
26
|
+
__export(exports, {
|
|
27
|
+
ironSession: () => ironSession
|
|
28
|
+
});
|
|
29
|
+
var import_iron_session = __toModule(require("iron-session"));
|
|
30
|
+
|
|
31
|
+
// src/getPropertyDescriptorForReqSession.ts
|
|
32
|
+
function getPropertyDescriptorForReqSession(session) {
|
|
33
|
+
return {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get() {
|
|
36
|
+
return session;
|
|
37
|
+
},
|
|
38
|
+
set(value) {
|
|
39
|
+
const keys = Object.keys(value);
|
|
40
|
+
const currentKeys = Object.keys(session);
|
|
41
|
+
currentKeys.forEach((key) => {
|
|
42
|
+
if (!keys.includes(key)) {
|
|
43
|
+
delete session[key];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
keys.forEach((key) => {
|
|
47
|
+
session[key] = value[key];
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// express/index.ts
|
|
54
|
+
function ironSession(sessionOptions) {
|
|
55
|
+
return async function ironSessionMiddleware(req, res, next) {
|
|
56
|
+
const session = await (0, import_iron_session.getIronSession)(req, res, sessionOptions);
|
|
57
|
+
Object.defineProperty(req, "session", getPropertyDescriptorForReqSession(session));
|
|
58
|
+
next();
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
ironSession
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../index.ts", "../../src/getPropertyDescriptorForReqSession.ts"],
|
|
4
|
+
"sourcesContent": ["import type { IronSessionOptions } from \"iron-session\";\nimport { getIronSession } from \"iron-session\";\nimport type { Request, Response, NextFunction } from \"express\";\nimport getPropertyDescriptorForReqSession from \"../src/getPropertyDescriptorForReqSession\";\n\nexport function ironSession(\n sessionOptions: IronSessionOptions,\n): (req: Request, res: Response, next: NextFunction) => Promise<void> {\n return async function ironSessionMiddleware(req, res, next) {\n const session = await getIronSession(req, res, sessionOptions);\n Object.defineProperty(\n req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n\n next();\n };\n}\n", "import type { IronSession } from \".\";\n\nexport default function getPropertyDescriptorForReqSession(\n session: IronSession,\n): PropertyDescriptor {\n return {\n enumerable: true,\n get() {\n return session;\n },\n set(value) {\n const keys = Object.keys(value);\n const currentKeys = Object.keys(session);\n\n currentKeys.forEach((key) => {\n if (!keys.includes(key)) {\n // @ts-ignore See comment in IronSessionData interface\n delete session[key];\n }\n });\n\n keys.forEach((key) => {\n // @ts-ignore See comment in IronSessionData interface\n session[key] = value[key];\n });\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AACA,0BAA+B;;;ACChB,4CACb,SACoB;AACpB,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,MAAM;AACJ,aAAO;AAAA;AAAA,IAET,IAAI,OAAO;AACT,YAAM,OAAO,OAAO,KAAK;AACzB,YAAM,cAAc,OAAO,KAAK;AAEhC,kBAAY,QAAQ,CAAC,QAAQ;AAC3B,YAAI,CAAC,KAAK,SAAS,MAAM;AAEvB,iBAAO,QAAQ;AAAA;AAAA;AAInB,WAAK,QAAQ,CAAC,QAAQ;AAEpB,gBAAQ,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;;;ADlBtB,qBACL,gBACoE;AACpE,SAAO,qCAAqC,KAAK,KAAK,MAAM;AAC1D,UAAM,UAAU,MAAM,wCAAe,KAAK,KAAK;AAC/C,WAAO,eACL,KACA,WACA,mCAAmC;AAGrC;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// express/index.ts
|
|
2
|
+
import { getIronSession } from "iron-session";
|
|
3
|
+
|
|
4
|
+
// src/getPropertyDescriptorForReqSession.ts
|
|
5
|
+
function getPropertyDescriptorForReqSession(session) {
|
|
6
|
+
return {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get() {
|
|
9
|
+
return session;
|
|
10
|
+
},
|
|
11
|
+
set(value) {
|
|
12
|
+
const keys = Object.keys(value);
|
|
13
|
+
const currentKeys = Object.keys(session);
|
|
14
|
+
currentKeys.forEach((key) => {
|
|
15
|
+
if (!keys.includes(key)) {
|
|
16
|
+
delete session[key];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
keys.forEach((key) => {
|
|
20
|
+
session[key] = value[key];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// express/index.ts
|
|
27
|
+
function ironSession(sessionOptions) {
|
|
28
|
+
return async function ironSessionMiddleware(req, res, next) {
|
|
29
|
+
const session = await getIronSession(req, res, sessionOptions);
|
|
30
|
+
Object.defineProperty(req, "session", getPropertyDescriptorForReqSession(session));
|
|
31
|
+
next();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
ironSession
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../index.ts", "../../src/getPropertyDescriptorForReqSession.ts"],
|
|
4
|
+
"sourcesContent": ["import type { IronSessionOptions } from \"iron-session\";\nimport { getIronSession } from \"iron-session\";\nimport type { Request, Response, NextFunction } from \"express\";\nimport getPropertyDescriptorForReqSession from \"../src/getPropertyDescriptorForReqSession\";\n\nexport function ironSession(\n sessionOptions: IronSessionOptions,\n): (req: Request, res: Response, next: NextFunction) => Promise<void> {\n return async function ironSessionMiddleware(req, res, next) {\n const session = await getIronSession(req, res, sessionOptions);\n Object.defineProperty(\n req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n\n next();\n };\n}\n", "import type { IronSession } from \".\";\n\nexport default function getPropertyDescriptorForReqSession(\n session: IronSession,\n): PropertyDescriptor {\n return {\n enumerable: true,\n get() {\n return session;\n },\n set(value) {\n const keys = Object.keys(value);\n const currentKeys = Object.keys(session);\n\n currentKeys.forEach((key) => {\n if (!keys.includes(key)) {\n // @ts-ignore See comment in IronSessionData interface\n delete session[key];\n }\n });\n\n keys.forEach((key) => {\n // @ts-ignore See comment in IronSessionData interface\n session[key] = value[key];\n });\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";AACA;;;ACCe,4CACb,SACoB;AACpB,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,MAAM;AACJ,aAAO;AAAA;AAAA,IAET,IAAI,OAAO;AACT,YAAM,OAAO,OAAO,KAAK;AACzB,YAAM,cAAc,OAAO,KAAK;AAEhC,kBAAY,QAAQ,CAAC,QAAQ;AAC3B,YAAI,CAAC,KAAK,SAAS,MAAM;AAEvB,iBAAO,QAAQ;AAAA;AAAA;AAInB,WAAK,QAAQ,CAAC,QAAQ;AAEpB,gBAAQ,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;;;ADlBtB,qBACL,gBACoE;AACpE,SAAO,qCAAqC,KAAK,KAAK,MAAM;AAC1D,UAAM,UAAU,MAAM,eAAe,KAAK,KAAK;AAC/C,WAAO,eACL,KACA,WACA,mCAAmC;AAGrC;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Request, Response } from "express";
|
|
2
|
+
import { ironSession } from ".";
|
|
3
|
+
const password = "Gbm49ATjnqnkCCCdhV4uDBhbfnPqsCW0";
|
|
4
|
+
const cookieName = "test";
|
|
5
|
+
|
|
6
|
+
// same structure as other tests otherwise linting will fail because you can have only one per running eslint
|
|
7
|
+
declare module "iron-session" {
|
|
8
|
+
interface IronSessionData {
|
|
9
|
+
user?: { id: number; meta?: string };
|
|
10
|
+
admin?: boolean;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
test("ironSession: req.session exists", async () => {
|
|
15
|
+
const wrappedHandler = ironSession({
|
|
16
|
+
password,
|
|
17
|
+
cookieName,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const req = getDefaultReq();
|
|
21
|
+
|
|
22
|
+
await wrappedHandler(req, getDefaultRes(), function () {
|
|
23
|
+
expect(req.session).toMatchInlineSnapshot(`Object {}`);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function getDefaultReq() {
|
|
28
|
+
return {
|
|
29
|
+
headers: {},
|
|
30
|
+
socket: {
|
|
31
|
+
encrypted: true,
|
|
32
|
+
},
|
|
33
|
+
} as unknown as Request;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getDefaultRes() {
|
|
37
|
+
return {
|
|
38
|
+
getHeader: jest.fn(),
|
|
39
|
+
setHeader: jest.fn(),
|
|
40
|
+
} as unknown as Response;
|
|
41
|
+
}
|
package/express/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IronSessionOptions } from "iron-session";
|
|
2
|
+
import { getIronSession } from "iron-session";
|
|
3
|
+
import type { Request, Response, NextFunction } from "express";
|
|
4
|
+
import getPropertyDescriptorForReqSession from "../src/getPropertyDescriptorForReqSession";
|
|
5
|
+
|
|
6
|
+
export function ironSession(
|
|
7
|
+
sessionOptions: IronSessionOptions,
|
|
8
|
+
): (req: Request, res: Response, next: NextFunction) => Promise<void> {
|
|
9
|
+
return async function ironSessionMiddleware(req, res, next) {
|
|
10
|
+
const session = await getIronSession(req, res, sessionOptions);
|
|
11
|
+
Object.defineProperty(
|
|
12
|
+
req,
|
|
13
|
+
"session",
|
|
14
|
+
getPropertyDescriptorForReqSession(session),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
next();
|
|
18
|
+
};
|
|
19
|
+
}
|
package/next/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { NextApiHandler, GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
|
|
2
|
+
import { IronSessionOptions } from 'iron-session';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
declare type NextGetServerSidePropsHandlerWithIronSession<P> = (context: NextGetSeverSideContextWithIronSession) => Promise<GetServerSidePropsResult<P>>;
|
|
12
|
-
declare function withIronSessionApiRoute(handler: NextApiHandlerWithIronSession, options: IronSessionOptions): NextApiHandlerWithIronSession;
|
|
13
|
-
declare function withIronSessionSsr<P>(handler: NextGetServerSidePropsHandlerWithIronSession<P>, options: IronSessionOptions): NextGetServerSidePropsHandlerWithIronSession<P>;
|
|
4
|
+
declare function withIronSessionApiRoute(handler: NextApiHandler, options: IronSessionOptions): NextApiHandler;
|
|
5
|
+
declare function withIronSessionSsr<P extends {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
} = {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}>(handler: (context: GetServerSidePropsContext) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>, options: IronSessionOptions): (context: GetServerSidePropsContext) => Promise<GetServerSidePropsResult<P>>;
|
|
14
10
|
|
|
15
|
-
export {
|
|
11
|
+
export { withIronSessionApiRoute, withIronSessionSsr };
|
package/next/dist/index.js
CHANGED
|
@@ -1,19 +1,74 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
__markAsModule(target);
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, module2, desc) => {
|
|
14
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(module2))
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
17
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __toModule = (module2) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// next/index.ts
|
|
26
|
+
__export(exports, {
|
|
27
|
+
withIronSessionApiRoute: () => withIronSessionApiRoute,
|
|
28
|
+
withIronSessionSsr: () => withIronSessionSsr
|
|
29
|
+
});
|
|
30
|
+
var import_iron_session = __toModule(require("iron-session"));
|
|
31
|
+
|
|
32
|
+
// src/getPropertyDescriptorForReqSession.ts
|
|
33
|
+
function getPropertyDescriptorForReqSession(session) {
|
|
34
|
+
return {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get() {
|
|
37
|
+
return session;
|
|
38
|
+
},
|
|
39
|
+
set(value) {
|
|
40
|
+
const keys = Object.keys(value);
|
|
41
|
+
const currentKeys = Object.keys(session);
|
|
42
|
+
currentKeys.forEach((key) => {
|
|
43
|
+
if (!keys.includes(key)) {
|
|
44
|
+
delete session[key];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
keys.forEach((key) => {
|
|
48
|
+
session[key] = value[key];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
1
54
|
// next/index.ts
|
|
2
|
-
import { getIronSession } from "iron-session";
|
|
3
55
|
function withIronSessionApiRoute(handler, options) {
|
|
4
56
|
return async function nextApiHandlerWrappedWithIronSession(req, res) {
|
|
5
|
-
|
|
57
|
+
const session = await (0, import_iron_session.getIronSession)(req, res, options);
|
|
58
|
+
Object.defineProperty(req, "session", getPropertyDescriptorForReqSession(session));
|
|
6
59
|
return handler(req, res);
|
|
7
60
|
};
|
|
8
61
|
}
|
|
9
62
|
function withIronSessionSsr(handler, options) {
|
|
10
63
|
return async function nextGetServerSidePropsHandlerWrappedWithIronSession(context) {
|
|
11
|
-
|
|
64
|
+
const session = await (0, import_iron_session.getIronSession)(context.req, context.res, options);
|
|
65
|
+
Object.defineProperty(context.req, "session", getPropertyDescriptorForReqSession(session));
|
|
12
66
|
return handler(context);
|
|
13
67
|
};
|
|
14
68
|
}
|
|
15
|
-
export
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
16
71
|
withIronSessionApiRoute,
|
|
17
72
|
withIronSessionSsr
|
|
18
|
-
};
|
|
73
|
+
});
|
|
19
74
|
//# sourceMappingURL=index.js.map
|
package/next/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../index.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../index.ts", "../../src/getPropertyDescriptorForReqSession.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n NextApiHandler,\n GetServerSidePropsContext,\n GetServerSidePropsResult,\n} from \"next\";\nimport type { IronSessionOptions } from \"iron-session\";\nimport { getIronSession } from \"iron-session\";\nimport getPropertyDescriptorForReqSession from \"../src/getPropertyDescriptorForReqSession\";\n\nexport function withIronSessionApiRoute(\n handler: NextApiHandler,\n options: IronSessionOptions,\n): NextApiHandler {\n return async function nextApiHandlerWrappedWithIronSession(req, res) {\n const session = await getIronSession(req, res, options);\n\n // we define req.session as being enumerable (so console.log(req) shows it)\n // and we also want to allow people to do:\n // req.session = { admin: true }; or req.session = {...req.session, admin: true};\n // req.session.save();\n Object.defineProperty(\n req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n return handler(req, res);\n };\n}\n\nexport function withIronSessionSsr<\n P extends { [key: string]: unknown } = { [key: string]: unknown },\n>(\n handler: (\n context: GetServerSidePropsContext,\n ) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>,\n options: IronSessionOptions,\n) {\n return async function nextGetServerSidePropsHandlerWrappedWithIronSession(\n context: GetServerSidePropsContext,\n ) {\n const session = await getIronSession(context.req, context.res, options);\n Object.defineProperty(\n context.req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n return handler(context);\n };\n}\n", "import type { IronSession } from \".\";\n\nexport default function getPropertyDescriptorForReqSession(\n session: IronSession,\n): PropertyDescriptor {\n return {\n enumerable: true,\n get() {\n return session;\n },\n set(value) {\n const keys = Object.keys(value);\n const currentKeys = Object.keys(session);\n\n currentKeys.forEach((key) => {\n if (!keys.includes(key)) {\n // @ts-ignore See comment in IronSessionData interface\n delete session[key];\n }\n });\n\n keys.forEach((key) => {\n // @ts-ignore See comment in IronSessionData interface\n session[key] = value[key];\n });\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAMA,0BAA+B;;;ACJhB,4CACb,SACoB;AACpB,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,MAAM;AACJ,aAAO;AAAA;AAAA,IAET,IAAI,OAAO;AACT,YAAM,OAAO,OAAO,KAAK;AACzB,YAAM,cAAc,OAAO,KAAK;AAEhC,kBAAY,QAAQ,CAAC,QAAQ;AAC3B,YAAI,CAAC,KAAK,SAAS,MAAM;AAEvB,iBAAO,QAAQ;AAAA;AAAA;AAInB,WAAK,QAAQ,CAAC,QAAQ;AAEpB,gBAAQ,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;;;ADdtB,iCACL,SACA,SACgB;AAChB,SAAO,oDAAoD,KAAK,KAAK;AACnE,UAAM,UAAU,MAAM,wCAAe,KAAK,KAAK;AAM/C,WAAO,eACL,KACA,WACA,mCAAmC;AAErC,WAAO,QAAQ,KAAK;AAAA;AAAA;AAIjB,4BAGL,SAGA,SACA;AACA,SAAO,mEACL,SACA;AACA,UAAM,UAAU,MAAM,wCAAe,QAAQ,KAAK,QAAQ,KAAK;AAC/D,WAAO,eACL,QAAQ,KACR,WACA,mCAAmC;AAErC,WAAO,QAAQ;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// next/index.ts
|
|
2
|
+
import { getIronSession } from "iron-session";
|
|
3
|
+
|
|
4
|
+
// src/getPropertyDescriptorForReqSession.ts
|
|
5
|
+
function getPropertyDescriptorForReqSession(session) {
|
|
6
|
+
return {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get() {
|
|
9
|
+
return session;
|
|
10
|
+
},
|
|
11
|
+
set(value) {
|
|
12
|
+
const keys = Object.keys(value);
|
|
13
|
+
const currentKeys = Object.keys(session);
|
|
14
|
+
currentKeys.forEach((key) => {
|
|
15
|
+
if (!keys.includes(key)) {
|
|
16
|
+
delete session[key];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
keys.forEach((key) => {
|
|
20
|
+
session[key] = value[key];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// next/index.ts
|
|
27
|
+
function withIronSessionApiRoute(handler, options) {
|
|
28
|
+
return async function nextApiHandlerWrappedWithIronSession(req, res) {
|
|
29
|
+
const session = await getIronSession(req, res, options);
|
|
30
|
+
Object.defineProperty(req, "session", getPropertyDescriptorForReqSession(session));
|
|
31
|
+
return handler(req, res);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function withIronSessionSsr(handler, options) {
|
|
35
|
+
return async function nextGetServerSidePropsHandlerWrappedWithIronSession(context) {
|
|
36
|
+
const session = await getIronSession(context.req, context.res, options);
|
|
37
|
+
Object.defineProperty(context.req, "session", getPropertyDescriptorForReqSession(session));
|
|
38
|
+
return handler(context);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
withIronSessionApiRoute,
|
|
43
|
+
withIronSessionSsr
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../index.ts", "../../src/getPropertyDescriptorForReqSession.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n NextApiHandler,\n GetServerSidePropsContext,\n GetServerSidePropsResult,\n} from \"next\";\nimport type { IronSessionOptions } from \"iron-session\";\nimport { getIronSession } from \"iron-session\";\nimport getPropertyDescriptorForReqSession from \"../src/getPropertyDescriptorForReqSession\";\n\nexport function withIronSessionApiRoute(\n handler: NextApiHandler,\n options: IronSessionOptions,\n): NextApiHandler {\n return async function nextApiHandlerWrappedWithIronSession(req, res) {\n const session = await getIronSession(req, res, options);\n\n // we define req.session as being enumerable (so console.log(req) shows it)\n // and we also want to allow people to do:\n // req.session = { admin: true }; or req.session = {...req.session, admin: true};\n // req.session.save();\n Object.defineProperty(\n req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n return handler(req, res);\n };\n}\n\nexport function withIronSessionSsr<\n P extends { [key: string]: unknown } = { [key: string]: unknown },\n>(\n handler: (\n context: GetServerSidePropsContext,\n ) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>,\n options: IronSessionOptions,\n) {\n return async function nextGetServerSidePropsHandlerWrappedWithIronSession(\n context: GetServerSidePropsContext,\n ) {\n const session = await getIronSession(context.req, context.res, options);\n Object.defineProperty(\n context.req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n return handler(context);\n };\n}\n", "import type { IronSession } from \".\";\n\nexport default function getPropertyDescriptorForReqSession(\n session: IronSession,\n): PropertyDescriptor {\n return {\n enumerable: true,\n get() {\n return session;\n },\n set(value) {\n const keys = Object.keys(value);\n const currentKeys = Object.keys(session);\n\n currentKeys.forEach((key) => {\n if (!keys.includes(key)) {\n // @ts-ignore See comment in IronSessionData interface\n delete session[key];\n }\n });\n\n keys.forEach((key) => {\n // @ts-ignore See comment in IronSessionData interface\n session[key] = value[key];\n });\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";AAMA;;;ACJe,4CACb,SACoB;AACpB,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,MAAM;AACJ,aAAO;AAAA;AAAA,IAET,IAAI,OAAO;AACT,YAAM,OAAO,OAAO,KAAK;AACzB,YAAM,cAAc,OAAO,KAAK;AAEhC,kBAAY,QAAQ,CAAC,QAAQ;AAC3B,YAAI,CAAC,KAAK,SAAS,MAAM;AAEvB,iBAAO,QAAQ;AAAA;AAAA;AAInB,WAAK,QAAQ,CAAC,QAAQ;AAEpB,gBAAQ,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;;;ADdtB,iCACL,SACA,SACgB;AAChB,SAAO,oDAAoD,KAAK,KAAK;AACnE,UAAM,UAAU,MAAM,eAAe,KAAK,KAAK;AAM/C,WAAO,eACL,KACA,WACA,mCAAmC;AAErC,WAAO,QAAQ,KAAK;AAAA;AAAA;AAIjB,4BAGL,SAGA,SACA;AACA,SAAO,mEACL,SACA;AACA,UAAM,UAAU,MAAM,eAAe,QAAQ,KAAK,QAAQ,KAAK;AAC/D,WAAO,eACL,QAAQ,KACR,WACA,mCAAmC;AAErC,WAAO,QAAQ;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/next/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NextApiHandler, GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
|
|
2
|
+
import { IronSessionOptions } from 'iron-session';
|
|
3
|
+
|
|
4
|
+
declare function withIronSessionApiRoute(handler: NextApiHandler, options: IronSessionOptions): NextApiHandler;
|
|
5
|
+
declare function withIronSessionSsr<P extends {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
} = {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}>(handler: (context: GetServerSidePropsContext) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>, options: IronSessionOptions): (context: GetServerSidePropsContext) => Promise<GetServerSidePropsResult<P>>;
|
|
10
|
+
|
|
11
|
+
export { withIronSessionApiRoute, withIronSessionSsr };
|
|
@@ -28,15 +28,41 @@ __export(exports, {
|
|
|
28
28
|
withIronSessionSsr: () => withIronSessionSsr
|
|
29
29
|
});
|
|
30
30
|
var import_iron_session = __toModule(require("iron-session"));
|
|
31
|
+
|
|
32
|
+
// src/getPropertyDescriptorForReqSession.ts
|
|
33
|
+
function getPropertyDescriptorForReqSession(session) {
|
|
34
|
+
return {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get() {
|
|
37
|
+
return session;
|
|
38
|
+
},
|
|
39
|
+
set(value) {
|
|
40
|
+
const keys = Object.keys(value);
|
|
41
|
+
const currentKeys = Object.keys(session);
|
|
42
|
+
currentKeys.forEach((key) => {
|
|
43
|
+
if (!keys.includes(key)) {
|
|
44
|
+
delete session[key];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
keys.forEach((key) => {
|
|
48
|
+
session[key] = value[key];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// next/index.ts
|
|
31
55
|
function withIronSessionApiRoute(handler, options) {
|
|
32
56
|
return async function nextApiHandlerWrappedWithIronSession(req, res) {
|
|
33
|
-
|
|
57
|
+
const session = await (0, import_iron_session.getIronSession)(req, res, options);
|
|
58
|
+
Object.defineProperty(req, "session", getPropertyDescriptorForReqSession(session));
|
|
34
59
|
return handler(req, res);
|
|
35
60
|
};
|
|
36
61
|
}
|
|
37
62
|
function withIronSessionSsr(handler, options) {
|
|
38
63
|
return async function nextGetServerSidePropsHandlerWrappedWithIronSession(context) {
|
|
39
|
-
|
|
64
|
+
const session = await (0, import_iron_session.getIronSession)(context.req, context.res, options);
|
|
65
|
+
Object.defineProperty(context.req, "session", getPropertyDescriptorForReqSession(session));
|
|
40
66
|
return handler(context);
|
|
41
67
|
};
|
|
42
68
|
}
|
|
@@ -45,4 +71,4 @@ function withIronSessionSsr(handler, options) {
|
|
|
45
71
|
withIronSessionApiRoute,
|
|
46
72
|
withIronSessionSsr
|
|
47
73
|
});
|
|
48
|
-
//# sourceMappingURL=index.
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../index.ts", "../../src/getPropertyDescriptorForReqSession.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n NextApiHandler,\n GetServerSidePropsContext,\n GetServerSidePropsResult,\n} from \"next\";\nimport type { IronSessionOptions } from \"iron-session\";\nimport { getIronSession } from \"iron-session\";\nimport getPropertyDescriptorForReqSession from \"../src/getPropertyDescriptorForReqSession\";\n\nexport function withIronSessionApiRoute(\n handler: NextApiHandler,\n options: IronSessionOptions,\n): NextApiHandler {\n return async function nextApiHandlerWrappedWithIronSession(req, res) {\n const session = await getIronSession(req, res, options);\n\n // we define req.session as being enumerable (so console.log(req) shows it)\n // and we also want to allow people to do:\n // req.session = { admin: true }; or req.session = {...req.session, admin: true};\n // req.session.save();\n Object.defineProperty(\n req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n return handler(req, res);\n };\n}\n\nexport function withIronSessionSsr<\n P extends { [key: string]: unknown } = { [key: string]: unknown },\n>(\n handler: (\n context: GetServerSidePropsContext,\n ) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>,\n options: IronSessionOptions,\n) {\n return async function nextGetServerSidePropsHandlerWrappedWithIronSession(\n context: GetServerSidePropsContext,\n ) {\n const session = await getIronSession(context.req, context.res, options);\n Object.defineProperty(\n context.req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n return handler(context);\n };\n}\n", "import type { IronSession } from \".\";\n\nexport default function getPropertyDescriptorForReqSession(\n session: IronSession,\n): PropertyDescriptor {\n return {\n enumerable: true,\n get() {\n return session;\n },\n set(value) {\n const keys = Object.keys(value);\n const currentKeys = Object.keys(session);\n\n currentKeys.forEach((key) => {\n if (!keys.includes(key)) {\n // @ts-ignore See comment in IronSessionData interface\n delete session[key];\n }\n });\n\n keys.forEach((key) => {\n // @ts-ignore See comment in IronSessionData interface\n session[key] = value[key];\n });\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAMA,0BAA+B;;;ACJhB,4CACb,SACoB;AACpB,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,MAAM;AACJ,aAAO;AAAA;AAAA,IAET,IAAI,OAAO;AACT,YAAM,OAAO,OAAO,KAAK;AACzB,YAAM,cAAc,OAAO,KAAK;AAEhC,kBAAY,QAAQ,CAAC,QAAQ;AAC3B,YAAI,CAAC,KAAK,SAAS,MAAM;AAEvB,iBAAO,QAAQ;AAAA;AAAA;AAInB,WAAK,QAAQ,CAAC,QAAQ;AAEpB,gBAAQ,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;;;ADdtB,iCACL,SACA,SACgB;AAChB,SAAO,oDAAoD,KAAK,KAAK;AACnE,UAAM,UAAU,MAAM,wCAAe,KAAK,KAAK;AAM/C,WAAO,eACL,KACA,WACA,mCAAmC;AAErC,WAAO,QAAQ,KAAK;AAAA;AAAA;AAIjB,4BAGL,SAGA,SACA;AACA,SAAO,mEACL,SACA;AACA,UAAM,UAAU,MAAM,wCAAe,QAAQ,KAAK,QAAQ,KAAK;AAC/D,WAAO,eACL,QAAQ,KACR,WACA,mCAAmC;AAErC,WAAO,QAAQ;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/next/index.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// next/index.ts
|
|
2
|
+
import { getIronSession } from "iron-session";
|
|
3
|
+
|
|
4
|
+
// src/getPropertyDescriptorForReqSession.ts
|
|
5
|
+
function getPropertyDescriptorForReqSession(session) {
|
|
6
|
+
return {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get() {
|
|
9
|
+
return session;
|
|
10
|
+
},
|
|
11
|
+
set(value) {
|
|
12
|
+
const keys = Object.keys(value);
|
|
13
|
+
const currentKeys = Object.keys(session);
|
|
14
|
+
currentKeys.forEach((key) => {
|
|
15
|
+
if (!keys.includes(key)) {
|
|
16
|
+
delete session[key];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
keys.forEach((key) => {
|
|
20
|
+
session[key] = value[key];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// next/index.ts
|
|
27
|
+
function withIronSessionApiRoute(handler, options) {
|
|
28
|
+
return async function nextApiHandlerWrappedWithIronSession(req, res) {
|
|
29
|
+
const session = await getIronSession(req, res, options);
|
|
30
|
+
Object.defineProperty(req, "session", getPropertyDescriptorForReqSession(session));
|
|
31
|
+
return handler(req, res);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function withIronSessionSsr(handler, options) {
|
|
35
|
+
return async function nextGetServerSidePropsHandlerWrappedWithIronSession(context) {
|
|
36
|
+
const session = await getIronSession(context.req, context.res, options);
|
|
37
|
+
Object.defineProperty(context.req, "session", getPropertyDescriptorForReqSession(session));
|
|
38
|
+
return handler(context);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
withIronSessionApiRoute,
|
|
43
|
+
withIronSessionSsr
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../index.ts", "../../src/getPropertyDescriptorForReqSession.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n NextApiHandler,\n GetServerSidePropsContext,\n GetServerSidePropsResult,\n} from \"next\";\nimport type { IronSessionOptions } from \"iron-session\";\nimport { getIronSession } from \"iron-session\";\nimport getPropertyDescriptorForReqSession from \"../src/getPropertyDescriptorForReqSession\";\n\nexport function withIronSessionApiRoute(\n handler: NextApiHandler,\n options: IronSessionOptions,\n): NextApiHandler {\n return async function nextApiHandlerWrappedWithIronSession(req, res) {\n const session = await getIronSession(req, res, options);\n\n // we define req.session as being enumerable (so console.log(req) shows it)\n // and we also want to allow people to do:\n // req.session = { admin: true }; or req.session = {...req.session, admin: true};\n // req.session.save();\n Object.defineProperty(\n req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n return handler(req, res);\n };\n}\n\nexport function withIronSessionSsr<\n P extends { [key: string]: unknown } = { [key: string]: unknown },\n>(\n handler: (\n context: GetServerSidePropsContext,\n ) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>,\n options: IronSessionOptions,\n) {\n return async function nextGetServerSidePropsHandlerWrappedWithIronSession(\n context: GetServerSidePropsContext,\n ) {\n const session = await getIronSession(context.req, context.res, options);\n Object.defineProperty(\n context.req,\n \"session\",\n getPropertyDescriptorForReqSession(session),\n );\n return handler(context);\n };\n}\n", "import type { IronSession } from \".\";\n\nexport default function getPropertyDescriptorForReqSession(\n session: IronSession,\n): PropertyDescriptor {\n return {\n enumerable: true,\n get() {\n return session;\n },\n set(value) {\n const keys = Object.keys(value);\n const currentKeys = Object.keys(session);\n\n currentKeys.forEach((key) => {\n if (!keys.includes(key)) {\n // @ts-ignore See comment in IronSessionData interface\n delete session[key];\n }\n });\n\n keys.forEach((key) => {\n // @ts-ignore See comment in IronSessionData interface\n session[key] = value[key];\n });\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";AAMA;;;ACJe,4CACb,SACoB;AACpB,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,MAAM;AACJ,aAAO;AAAA;AAAA,IAET,IAAI,OAAO;AACT,YAAM,OAAO,OAAO,KAAK;AACzB,YAAM,cAAc,OAAO,KAAK;AAEhC,kBAAY,QAAQ,CAAC,QAAQ;AAC3B,YAAI,CAAC,KAAK,SAAS,MAAM;AAEvB,iBAAO,QAAQ;AAAA;AAAA;AAInB,WAAK,QAAQ,CAAC,QAAQ;AAEpB,gBAAQ,OAAO,MAAM;AAAA;AAAA;AAAA;AAAA;;;ADdtB,iCACL,SACA,SACgB;AAChB,SAAO,oDAAoD,KAAK,KAAK;AACnE,UAAM,UAAU,MAAM,eAAe,KAAK,KAAK;AAM/C,WAAO,eACL,KACA,WACA,mCAAmC;AAErC,WAAO,QAAQ,KAAK;AAAA;AAAA;AAIjB,4BAGL,SAGA,SACA;AACA,SAAO,mEACL,SACA;AACA,UAAM,UAAU,MAAM,eAAe,QAAQ,KAAK,QAAQ,KAAK;AAC/D,WAAO,eACL,QAAQ,KACR,WACA,mCAAmC;AAErC,WAAO,QAAQ;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|