@aws-amplify/adapter-nextjs 0.0.2-console-preview.2f5ba46.0 → 0.0.2-console-preview.1053355.0
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/lib/utils/createCookieStorageAdapterFromNextServerContext.js +20 -7
- package/lib/utils/createCookieStorageAdapterFromNextServerContext.js.map +1 -1
- package/lib-esm/utils/createCookieStorageAdapterFromNextServerContext.js +21 -8
- package/lib-esm/utils/createCookieStorageAdapterFromNextServerContext.js.map +1 -1
- package/package.json +4 -3
- package/src/utils/createCookieStorageAdapterFromNextServerContext.ts +31 -15
|
@@ -16,11 +16,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.createCookieStorageAdapterFromNextServerContext = exports.DATE_IN_THE_PAST = void 0;
|
|
17
17
|
var server_1 = require("next/server");
|
|
18
18
|
var adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
19
|
-
var http_1 = require("http");
|
|
20
19
|
exports.DATE_IN_THE_PAST = new Date(0);
|
|
21
20
|
var createCookieStorageAdapterFromNextServerContext = function (context) {
|
|
22
|
-
var _a = context,
|
|
23
|
-
|
|
21
|
+
var _a = context, req = _a.request, res = _a.response;
|
|
22
|
+
// When the server context is from `getServerSideProps`, the `req` is an instance
|
|
23
|
+
// of IncomingMessage, and the `res` is an instance of ServerResponse.
|
|
24
|
+
// We cannot import these two classes here from `http` as it breaks in Next
|
|
25
|
+
// Edge Runtime. Hence, we check the methods that we need to use for creating
|
|
26
|
+
// cookie adapter.
|
|
27
|
+
if (req &&
|
|
28
|
+
res &&
|
|
29
|
+
Object.prototype.toString.call(req.cookies) === '[object Object]' &&
|
|
30
|
+
typeof res.setHeader === 'function') {
|
|
31
|
+
return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
|
|
32
|
+
}
|
|
33
|
+
var _b = context, request = _b.request, response = _b.response;
|
|
34
|
+
// When the server context is from `middleware`, the `request` is an instance
|
|
35
|
+
// of `NextRequest`.
|
|
36
|
+
// When the server context is from a route handler, the `request` is an `Proxy`
|
|
37
|
+
// wrapped `Request`.
|
|
38
|
+
// The `NextRequest` and the `Proxy` are sharing the same interface by Next
|
|
39
|
+
// implementation. So we don't need to detect the difference.
|
|
40
|
+
if (request && response) {
|
|
24
41
|
if (response instanceof server_1.NextResponse) {
|
|
25
42
|
return createCookieStorageAdapterFromNextRequestAndNextResponse(request, response);
|
|
26
43
|
}
|
|
@@ -32,10 +49,6 @@ var createCookieStorageAdapterFromNextServerContext = function (context) {
|
|
|
32
49
|
if (typeof cookies === 'function') {
|
|
33
50
|
return createCookieStorageAdapterFromNextCookies(cookies);
|
|
34
51
|
}
|
|
35
|
-
var _b = context, req = _b.request, res = _b.response;
|
|
36
|
-
if (req instanceof http_1.IncomingMessage && res instanceof http_1.ServerResponse) {
|
|
37
|
-
return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
|
|
38
|
-
}
|
|
39
52
|
// This should not happen normally.
|
|
40
53
|
throw new adapter_core_1.AmplifyServerContextError({
|
|
41
54
|
message: 'Attempted to create cookie storage adapter from an unsupported Next.js server context.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sourceRoot":"","sources":["../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;AAEtC,sCAAwD;AAExD,yEAGkD;
|
|
1
|
+
{"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sourceRoot":"","sources":["../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;AAEtC,sCAAwD;AAExD,yEAGkD;AAErC,QAAA,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,IAAM,+CAA+C,GAAG,UAC9D,OAA2B;IAErB,IAAA,KACL,OA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ign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
return __assign.apply(this, arguments);
|
|
13
13
|
};
|
|
14
|
-
import {
|
|
14
|
+
import { NextResponse } from 'next/server';
|
|
15
15
|
import { AmplifyServerContextError, } from '@aws-amplify/core/internals/adapter-core';
|
|
16
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
17
16
|
export var DATE_IN_THE_PAST = new Date(0);
|
|
18
17
|
export var createCookieStorageAdapterFromNextServerContext = function (context) {
|
|
19
|
-
var _a = context,
|
|
20
|
-
|
|
18
|
+
var _a = context, req = _a.request, res = _a.response;
|
|
19
|
+
// When the server context is from `getServerSideProps`, the `req` is an instance
|
|
20
|
+
// of IncomingMessage, and the `res` is an instance of ServerResponse.
|
|
21
|
+
// We cannot import these two classes here from `http` as it breaks in Next
|
|
22
|
+
// Edge Runtime. Hence, we check the methods that we need to use for creating
|
|
23
|
+
// cookie adapter.
|
|
24
|
+
if (req &&
|
|
25
|
+
res &&
|
|
26
|
+
Object.prototype.toString.call(req.cookies) === '[object Object]' &&
|
|
27
|
+
typeof res.setHeader === 'function') {
|
|
28
|
+
return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
|
|
29
|
+
}
|
|
30
|
+
var _b = context, request = _b.request, response = _b.response;
|
|
31
|
+
// When the server context is from `middleware`, the `request` is an instance
|
|
32
|
+
// of `NextRequest`.
|
|
33
|
+
// When the server context is from a route handler, the `request` is an `Proxy`
|
|
34
|
+
// wrapped `Request`.
|
|
35
|
+
// The `NextRequest` and the `Proxy` are sharing the same interface by Next
|
|
36
|
+
// implementation. So we don't need to detect the difference.
|
|
37
|
+
if (request && response) {
|
|
21
38
|
if (response instanceof NextResponse) {
|
|
22
39
|
return createCookieStorageAdapterFromNextRequestAndNextResponse(request, response);
|
|
23
40
|
}
|
|
@@ -29,10 +46,6 @@ export var createCookieStorageAdapterFromNextServerContext = function (context)
|
|
|
29
46
|
if (typeof cookies === 'function') {
|
|
30
47
|
return createCookieStorageAdapterFromNextCookies(cookies);
|
|
31
48
|
}
|
|
32
|
-
var _b = context, req = _b.request, res = _b.response;
|
|
33
|
-
if (req instanceof IncomingMessage && res instanceof ServerResponse) {
|
|
34
|
-
return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
|
|
35
|
-
}
|
|
36
49
|
// This should not happen normally.
|
|
37
50
|
throw new AmplifyServerContextError({
|
|
38
51
|
message: 'Attempted to create cookie storage adapter from an unsupported Next.js server context.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sourceRoot":"","sources":["../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;AAEtC,OAAO,
|
|
1
|
+
{"version":3,"file":"createCookieStorageAdapterFromNextServerContext.js","sourceRoot":"","sources":["../../src/utils/createCookieStorageAdapterFromNextServerContext.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;AAEtC,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EACN,yBAAyB,GAEzB,MAAM,0CAA0C,CAAC;AAElD,MAAM,CAAC,IAAM,gBAAgB,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AAE5C,MAAM,CAAC,IAAM,+CAA+C,GAAG,UAC9D,OAA2B;IAErB,IAAA,KACL,OAAwD,EADxC,GAAG,aAAA,EAAY,GAAG,cACsB,CAAC;IAE1D,iFAAiF;IACjF,sEAAsE;IACtE,2EAA2E;IAC3E,6EAA6E;IAC7E,kBAAkB;IAClB,IACC,GAAG;QACH,GAAG;QACH,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,iBAAiB;QACjE,OAAO,GAAG,CAAC,SAAS,KAAK,UAAU,EAClC;QACD,OAAO,uDAAuD,CAAC,GAAG,EAAE,GAAG,CAAC,C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AC,CAAC;AAEF,IAAM,yBAAyB,GAAG,UACjC,OAAuC;IAE/B,IAAA,OAAO,GAAiD,OAAO,QAAxD,EAAE,MAAM,GAAyC,OAAO,OAAhD,EAAE,MAAM,GAAiC,OAAO,OAAxC,EAAE,QAAQ,GAAuB,OAAO,SAA9B,EAAE,QAAQ,GAAa,OAAO,SAApB,EAAE,MAAM,GAAK,OAAO,OAAZ,CAAa;IACxE,IAAM,iBAAiB,GAAa,EAAE,CAAC;IACvC,IAAI,MAAM,EAAE;QACX,iBAAiB,CAAC,IAAI,CAAC,iBAAU,MAAM,CAAE,CAAC,CAAC;KAC3C;IACD,IAAI,OAAO,EAAE;QACZ,iBAAiB,CAAC,IAAI,CAAC,kBAAW,OAAO,CAAC,WAAW,EAAE,CAAE,CAAC,CAAC;KAC3D;IACD,IAAI,QAAQ,EAAE;QACb,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KACnC;IACD,IAAI,QAAQ,EAAE;QACb,iBAAiB,CAAC,IAAI,CAAC,mBAAY,QAAQ,CAAE,CAAC,CAAC;KAC/C;IACD,IAAI,MAAM,EAAE;QACX,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACjC;IACD,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@types/node": "^20.3.1",
|
|
16
16
|
"@types/react": "^18.2.13",
|
|
17
17
|
"@types/react-dom": "^18.2.6",
|
|
18
|
-
"aws-amplify": "6.0.1-console-preview.
|
|
18
|
+
"aws-amplify": "6.0.1-console-preview.1053355.0+1053355",
|
|
19
19
|
"jest-fetch-mock": "3.0.3",
|
|
20
20
|
"next": ">= 13.4.0 < 14.0.0",
|
|
21
21
|
"typescript": "5.1.6"
|
|
@@ -91,6 +91,7 @@
|
|
|
91
91
|
"license": "Apache-2.0",
|
|
92
92
|
"main": "./lib/index.js",
|
|
93
93
|
"module": "./lib-esm/index.js",
|
|
94
|
+
"sideEffects": false,
|
|
94
95
|
"scripts": {
|
|
95
96
|
"build": "npm run clean && npm run build:esm && npm run build:cjs",
|
|
96
97
|
"build-with-test": "npm test && npm run build",
|
|
@@ -106,6 +107,6 @@
|
|
|
106
107
|
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
|
|
107
108
|
},
|
|
108
109
|
"typings": "./lib-esm/index.d.ts",
|
|
109
|
-
"version": "0.0.2-console-preview.
|
|
110
|
-
"gitHead": "
|
|
110
|
+
"version": "0.0.2-console-preview.1053355.0+1053355",
|
|
111
|
+
"gitHead": "1053355d0160296ba83ed4ae1b4f8cf759717f71"
|
|
111
112
|
}
|
|
@@ -7,18 +7,41 @@ import {
|
|
|
7
7
|
AmplifyServerContextError,
|
|
8
8
|
CookieStorage,
|
|
9
9
|
} from '@aws-amplify/core/internals/adapter-core';
|
|
10
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
11
10
|
|
|
12
11
|
export const DATE_IN_THE_PAST = new Date(0);
|
|
13
12
|
|
|
14
13
|
export const createCookieStorageAdapterFromNextServerContext = (
|
|
15
14
|
context: NextServer.Context
|
|
16
15
|
): CookieStorage.Adapter => {
|
|
17
|
-
const { request, response } =
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const { request: req, response: res } =
|
|
17
|
+
context as Partial<NextServer.GetServerSidePropsContext>;
|
|
18
|
+
|
|
19
|
+
// When the server context is from `getServerSideProps`, the `req` is an instance
|
|
20
|
+
// of IncomingMessage, and the `res` is an instance of ServerResponse.
|
|
21
|
+
// We cannot import these two classes here from `http` as it breaks in Next
|
|
22
|
+
// Edge Runtime. Hence, we check the methods that we need to use for creating
|
|
23
|
+
// cookie adapter.
|
|
24
|
+
if (
|
|
25
|
+
req &&
|
|
26
|
+
res &&
|
|
27
|
+
Object.prototype.toString.call(req.cookies) === '[object Object]' &&
|
|
28
|
+
typeof res.setHeader === 'function'
|
|
29
|
+
) {
|
|
30
|
+
return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
|
|
31
|
+
}
|
|
20
32
|
|
|
21
|
-
|
|
33
|
+
const { request, response } = context as Partial<
|
|
34
|
+
| NextServer.NextRequestAndNextResponseContext
|
|
35
|
+
| NextServer.NextRequestAndResponseContext
|
|
36
|
+
>;
|
|
37
|
+
|
|
38
|
+
// When the server context is from `middleware`, the `request` is an instance
|
|
39
|
+
// of `NextRequest`.
|
|
40
|
+
// When the server context is from a route handler, the `request` is an `Proxy`
|
|
41
|
+
// wrapped `Request`.
|
|
42
|
+
// The `NextRequest` and the `Proxy` are sharing the same interface by Next
|
|
43
|
+
// implementation. So we don't need to detect the difference.
|
|
44
|
+
if (request && response) {
|
|
22
45
|
if (response instanceof NextResponse) {
|
|
23
46
|
return createCookieStorageAdapterFromNextRequestAndNextResponse(
|
|
24
47
|
request,
|
|
@@ -32,21 +55,14 @@ export const createCookieStorageAdapterFromNextServerContext = (
|
|
|
32
55
|
}
|
|
33
56
|
}
|
|
34
57
|
|
|
35
|
-
const { cookies } = context as
|
|
36
|
-
| NextServer.
|
|
37
|
-
|
|
58
|
+
const { cookies } = context as Partial<
|
|
59
|
+
NextServer.ServerComponentContext | NextServer.ServerActionContext
|
|
60
|
+
>;
|
|
38
61
|
|
|
39
62
|
if (typeof cookies === 'function') {
|
|
40
63
|
return createCookieStorageAdapterFromNextCookies(cookies);
|
|
41
64
|
}
|
|
42
65
|
|
|
43
|
-
const { request: req, response: res } =
|
|
44
|
-
context as NextServer.GetServerSidePropsContext;
|
|
45
|
-
|
|
46
|
-
if (req instanceof IncomingMessage && res instanceof ServerResponse) {
|
|
47
|
-
return createCookieStorageAdapterFromGetServerSidePropsContext(req, res);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
66
|
// This should not happen normally.
|
|
51
67
|
throw new AmplifyServerContextError({
|
|
52
68
|
message:
|