@aws-amplify/adapter-nextjs 0.0.2-console-preview.1053355.0 → 0.0.2-console-preview.957cda4.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/runWithAmplifyServerContext.js +7 -6
- package/lib/runWithAmplifyServerContext.js.map +1 -1
- package/lib/utils/getAmplifyConfig.d.ts +1 -1
- package/lib/withAmplify.d.ts +15 -2
- package/lib/withAmplify.js +15 -4
- package/lib/withAmplify.js.map +1 -1
- package/lib-esm/runWithAmplifyServerContext.js +7 -6
- package/lib-esm/runWithAmplifyServerContext.js.map +1 -1
- package/lib-esm/utils/getAmplifyConfig.d.ts +1 -1
- package/lib-esm/withAmplify.d.ts +15 -2
- package/lib-esm/withAmplify.js +15 -4
- package/lib-esm/withAmplify.js.map +1 -1
- package/package.json +3 -3
- package/src/runWithAmplifyServerContext.ts +5 -5
- package/src/utils/getAmplifyConfig.ts +1 -1
- package/src/withAmplify.ts +15 -3
|
@@ -51,12 +51,13 @@ var runWithAmplifyServerContext = function (_a) {
|
|
|
51
51
|
// When the Auth config is presented, attempt to create a Amplify server
|
|
52
52
|
// context with token and credentials provider.
|
|
53
53
|
if (amplifyConfig.Auth) {
|
|
54
|
-
keyValueStorage =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
keyValueStorage =
|
|
55
|
+
// When `null` is passed as the value of `nextServerContext`, opt-in
|
|
56
|
+
// unauthenticated role (primarily for static rendering). It's
|
|
57
|
+
// safe to use the singleton `MemoryKeyValueStorage` here, as the
|
|
58
|
+
// static rendering uses the same unauthenticated role cross-sever.
|
|
59
|
+
nextServerContext === null
|
|
60
|
+
? core_1.MemoryKeyValueStorage
|
|
60
61
|
: (0, adapter_core_1.createKeyValueStorageFromCookieStorageAdapter)((0, utils_1.createCookieStorageAdapterFromNextServerContext)(nextServerContext));
|
|
61
62
|
credentialsProvider = (0, adapter_core_1.createAWSCredentialsAndIdentityIdProvider)(amplifyConfig.Auth, keyValueStorage);
|
|
62
63
|
tokenProvider = (0, adapter_core_1.createUserPoolsTokenProvider)(amplifyConfig.Auth, keyValueStorage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runWithAmplifyServerContext.js","sourceRoot":"","sources":["../src/runWithAmplifyServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,iCAGiB;AACjB,0CAA0D;AAC1D,mEAK4C;AAErC,IAAM,2BAA2B,GACvC,UAAO,EAAgC;QAA9B,iBAAiB,uBAAA,EAAE,SAAS,eAAA;;;;YAM9B,aAAa,GAAG,IAAA,wBAAgB,GAAE,CAAC;YAEzC,wEAAwE;YACxE,+CAA+C;YAC/C,IAAI,aAAa,CAAC,IAAI,EAAE;gBACjB,eAAe,
|
|
1
|
+
{"version":3,"file":"runWithAmplifyServerContext.js","sourceRoot":"","sources":["../src/runWithAmplifyServerContext.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,iCAGiB;AACjB,0CAA0D;AAC1D,mEAK4C;AAErC,IAAM,2BAA2B,GACvC,UAAO,EAAgC;QAA9B,iBAAiB,uBAAA,EAAE,SAAS,eAAA;;;;YAM9B,aAAa,GAAG,IAAA,wBAAgB,GAAE,CAAC;YAEzC,wEAAwE;YACxE,+CAA+C;YAC/C,IAAI,aAAa,CAAC,IAAI,EAAE;gBACjB,eAAe;gBACpB,oEAAoE;gBACpE,8DAA8D;gBAC9D,iEAAiE;gBACjE,mEAAmE;gBACnE,iBAAiB,KAAK,IAAI;oBACzB,CAAC,CAAC,4BAAqB;oBACvB,CAAC,CAAC,IAAA,4DAA6C,EAC7C,IAAA,uDAA+C,EAAC,iBAAiB,CAAC,CACjE,CAAC;gBACA,mBAAmB,GAAG,IAAA,wDAAyC,EACpE,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBACI,aAAa,GAAG,IAAA,2CAA4B,EACjD,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBAEF,sBAAO,IAAA,0CAA+B,EACrC,aAAa,EACb;wBACC,IAAI,EAAE,EAAE,mBAAmB,qBAAA,EAAE,aAAa,eAAA,EAAE;qBAC5C,EACD,SAAS,CACT,EAAC;aACF;YAED,oEAAoE;YACpE,+CAA+C;YAC/C,sBAAO,IAAA,0CAA+B,EAAC,aAAa,EAAE,EAAE,EAAE,SAAS,CAAC,EAAC;;;CACrE,CAAC;AA3CU,QAAA,2BAA2B,+BA2CrC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ResourcesConfig } from '
|
|
1
|
+
import { ResourcesConfig } from 'aws-amplify';
|
|
2
2
|
export declare const getAmplifyConfig: () => ResourcesConfig;
|
package/lib/withAmplify.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import { ResourcesConfig } from '
|
|
1
|
+
import { ResourcesConfig } from 'aws-amplify';
|
|
2
2
|
import { NextConfig } from 'next';
|
|
3
3
|
/**
|
|
4
4
|
* Merges the `amplifyConfig` into the `nextConfig.env`.
|
|
5
|
+
*
|
|
5
6
|
* @param nextConfig The next config for a Next.js app.
|
|
6
|
-
* @param amplifyConfig
|
|
7
|
+
* @param amplifyConfig The Amplify configuration.
|
|
8
|
+
*
|
|
9
|
+
* **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js`
|
|
10
|
+
* file, you need to use {@link parseAmplifyConfig} to reformat the configuration.
|
|
11
|
+
* E.g.
|
|
12
|
+
* ```javascript
|
|
13
|
+
* const { parseAmplifyConfig } = require('aws-amplify');
|
|
14
|
+
* const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify');
|
|
15
|
+
* const config = require('./src/aws-exports');
|
|
16
|
+
*
|
|
17
|
+
* const nextConfig = {};
|
|
18
|
+
* module.exports = withAmplify(nextConfig, parseAmplifyConfig(config));
|
|
19
|
+
* ```
|
|
7
20
|
* @returns The updated `nextConfig`.
|
|
8
21
|
*/
|
|
9
22
|
export declare const withAmplify: (nextConfig: NextConfig, amplifyConfig: ResourcesConfig) => NextConfig;
|
package/lib/withAmplify.js
CHANGED
|
@@ -19,14 +19,25 @@ exports.withAmplify = void 0;
|
|
|
19
19
|
// is not being transpiled by Next.js.
|
|
20
20
|
/**
|
|
21
21
|
* Merges the `amplifyConfig` into the `nextConfig.env`.
|
|
22
|
+
*
|
|
22
23
|
* @param nextConfig The next config for a Next.js app.
|
|
23
|
-
* @param amplifyConfig
|
|
24
|
+
* @param amplifyConfig The Amplify configuration.
|
|
25
|
+
*
|
|
26
|
+
* **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js`
|
|
27
|
+
* file, you need to use {@link parseAmplifyConfig} to reformat the configuration.
|
|
28
|
+
* E.g.
|
|
29
|
+
* ```javascript
|
|
30
|
+
* const { parseAmplifyConfig } = require('aws-amplify');
|
|
31
|
+
* const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify');
|
|
32
|
+
* const config = require('./src/aws-exports');
|
|
33
|
+
*
|
|
34
|
+
* const nextConfig = {};
|
|
35
|
+
* module.exports = withAmplify(nextConfig, parseAmplifyConfig(config));
|
|
36
|
+
* ```
|
|
24
37
|
* @returns The updated `nextConfig`.
|
|
25
38
|
*/
|
|
26
39
|
var withAmplify = function (nextConfig, amplifyConfig) {
|
|
27
|
-
nextConfig.env = __assign(__assign({}, nextConfig.env), {
|
|
28
|
-
// TODO(Hui): follow up the validation of the amplifyConfig.
|
|
29
|
-
amplifyConfig: JSON.stringify(amplifyConfig) });
|
|
40
|
+
nextConfig.env = __assign(__assign({}, nextConfig.env), { amplifyConfig: JSON.stringify(amplifyConfig) });
|
|
30
41
|
return nextConfig;
|
|
31
42
|
};
|
|
32
43
|
exports.withAmplify = withAmplify;
|
package/lib/withAmplify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withAmplify.js","sourceRoot":"","sources":["../src/withAmplify.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;AAKtC,oEAAoE;AACpE,2EAA2E;AAC3E,sCAAsC;AAEtC
|
|
1
|
+
{"version":3,"file":"withAmplify.js","sourceRoot":"","sources":["../src/withAmplify.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;AAKtC,oEAAoE;AACpE,2EAA2E;AAC3E,sCAAsC;AAEtC;;;;;;;;;;;;;;;;;;GAkBG;AACI,IAAM,WAAW,GAAG,UAC1B,UAAsB,EACtB,aAA8B;IAE9B,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG,KACjB,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAC5C,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAVW,QAAA,WAAW,eAUtB"}
|
|
@@ -48,12 +48,13 @@ export var runWithAmplifyServerContext = function (_a) {
|
|
|
48
48
|
// When the Auth config is presented, attempt to create a Amplify server
|
|
49
49
|
// context with token and credentials provider.
|
|
50
50
|
if (amplifyConfig.Auth) {
|
|
51
|
-
keyValueStorage =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
keyValueStorage =
|
|
52
|
+
// When `null` is passed as the value of `nextServerContext`, opt-in
|
|
53
|
+
// unauthenticated role (primarily for static rendering). It's
|
|
54
|
+
// safe to use the singleton `MemoryKeyValueStorage` here, as the
|
|
55
|
+
// static rendering uses the same unauthenticated role cross-sever.
|
|
56
|
+
nextServerContext === null
|
|
57
|
+
? MemoryKeyValueStorage
|
|
57
58
|
: createKeyValueStorageFromCookieStorageAdapter(createCookieStorageAdapterFromNextServerContext(nextServerContext));
|
|
58
59
|
credentialsProvider = createAWSCredentialsAndIdentityIdProvider(amplifyConfig.Auth, keyValueStorage);
|
|
59
60
|
tokenProvider = createUserPoolsTokenProvider(amplifyConfig.Auth, keyValueStorage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runWithAmplifyServerContext.js","sourceRoot":"","sources":["../src/runWithAmplifyServerContext.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,OAAO,EACN,+CAA+C,EAC/C,gBAAgB,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACN,yCAAyC,EACzC,6CAA6C,EAC7C,4BAA4B,EAC5B,2BAA2B,IAAI,+BAA+B,GAC9D,MAAM,oCAAoC,CAAC;AAE5C,MAAM,CAAC,IAAM,2BAA2B,GACvC,UAAO,EAAgC;QAA9B,iBAAiB,uBAAA,EAAE,SAAS,eAAA;;;;YAM9B,aAAa,GAAG,gBAAgB,EAAE,CAAC;YAEzC,wEAAwE;YACxE,+CAA+C;YAC/C,IAAI,aAAa,CAAC,IAAI,EAAE;gBACjB,eAAe,
|
|
1
|
+
{"version":3,"file":"runWithAmplifyServerContext.js","sourceRoot":"","sources":["../src/runWithAmplifyServerContext.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtC,OAAO,EACN,+CAA+C,EAC/C,gBAAgB,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACN,yCAAyC,EACzC,6CAA6C,EAC7C,4BAA4B,EAC5B,2BAA2B,IAAI,+BAA+B,GAC9D,MAAM,oCAAoC,CAAC;AAE5C,MAAM,CAAC,IAAM,2BAA2B,GACvC,UAAO,EAAgC;QAA9B,iBAAiB,uBAAA,EAAE,SAAS,eAAA;;;;YAM9B,aAAa,GAAG,gBAAgB,EAAE,CAAC;YAEzC,wEAAwE;YACxE,+CAA+C;YAC/C,IAAI,aAAa,CAAC,IAAI,EAAE;gBACjB,eAAe;gBACpB,oEAAoE;gBACpE,8DAA8D;gBAC9D,iEAAiE;gBACjE,mEAAmE;gBACnE,iBAAiB,KAAK,IAAI;oBACzB,CAAC,CAAC,qBAAqB;oBACvB,CAAC,CAAC,6CAA6C,CAC7C,+CAA+C,CAAC,iBAAiB,CAAC,CACjE,CAAC;gBACA,mBAAmB,GAAG,yCAAyC,CACpE,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBACI,aAAa,GAAG,4BAA4B,CACjD,aAAa,CAAC,IAAI,EAClB,eAAe,CACf,CAAC;gBAEF,sBAAO,+BAA+B,CACrC,aAAa,EACb;wBACC,IAAI,EAAE,EAAE,mBAAmB,qBAAA,EAAE,aAAa,eAAA,EAAE;qBAC5C,EACD,SAAS,CACT,EAAC;aACF;YAED,oEAAoE;YACpE,+CAA+C;YAC/C,sBAAO,+BAA+B,CAAC,aAAa,EAAE,EAAE,EAAE,SAAS,CAAC,EAAC;;;CACrE,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ResourcesConfig } from '
|
|
1
|
+
import { ResourcesConfig } from 'aws-amplify';
|
|
2
2
|
export declare const getAmplifyConfig: () => ResourcesConfig;
|
package/lib-esm/withAmplify.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import { ResourcesConfig } from '
|
|
1
|
+
import { ResourcesConfig } from 'aws-amplify';
|
|
2
2
|
import { NextConfig } from 'next';
|
|
3
3
|
/**
|
|
4
4
|
* Merges the `amplifyConfig` into the `nextConfig.env`.
|
|
5
|
+
*
|
|
5
6
|
* @param nextConfig The next config for a Next.js app.
|
|
6
|
-
* @param amplifyConfig
|
|
7
|
+
* @param amplifyConfig The Amplify configuration.
|
|
8
|
+
*
|
|
9
|
+
* **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js`
|
|
10
|
+
* file, you need to use {@link parseAmplifyConfig} to reformat the configuration.
|
|
11
|
+
* E.g.
|
|
12
|
+
* ```javascript
|
|
13
|
+
* const { parseAmplifyConfig } = require('aws-amplify');
|
|
14
|
+
* const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify');
|
|
15
|
+
* const config = require('./src/aws-exports');
|
|
16
|
+
*
|
|
17
|
+
* const nextConfig = {};
|
|
18
|
+
* module.exports = withAmplify(nextConfig, parseAmplifyConfig(config));
|
|
19
|
+
* ```
|
|
7
20
|
* @returns The updated `nextConfig`.
|
|
8
21
|
*/
|
|
9
22
|
export declare const withAmplify: (nextConfig: NextConfig, amplifyConfig: ResourcesConfig) => NextConfig;
|
package/lib-esm/withAmplify.js
CHANGED
|
@@ -16,14 +16,25 @@ var __assign = (this && this.__assign) || function () {
|
|
|
16
16
|
// is not being transpiled by Next.js.
|
|
17
17
|
/**
|
|
18
18
|
* Merges the `amplifyConfig` into the `nextConfig.env`.
|
|
19
|
+
*
|
|
19
20
|
* @param nextConfig The next config for a Next.js app.
|
|
20
|
-
* @param amplifyConfig
|
|
21
|
+
* @param amplifyConfig The Amplify configuration.
|
|
22
|
+
*
|
|
23
|
+
* **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js`
|
|
24
|
+
* file, you need to use {@link parseAmplifyConfig} to reformat the configuration.
|
|
25
|
+
* E.g.
|
|
26
|
+
* ```javascript
|
|
27
|
+
* const { parseAmplifyConfig } = require('aws-amplify');
|
|
28
|
+
* const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify');
|
|
29
|
+
* const config = require('./src/aws-exports');
|
|
30
|
+
*
|
|
31
|
+
* const nextConfig = {};
|
|
32
|
+
* module.exports = withAmplify(nextConfig, parseAmplifyConfig(config));
|
|
33
|
+
* ```
|
|
21
34
|
* @returns The updated `nextConfig`.
|
|
22
35
|
*/
|
|
23
36
|
export var withAmplify = function (nextConfig, amplifyConfig) {
|
|
24
|
-
nextConfig.env = __assign(__assign({}, nextConfig.env), {
|
|
25
|
-
// TODO(Hui): follow up the validation of the amplifyConfig.
|
|
26
|
-
amplifyConfig: JSON.stringify(amplifyConfig) });
|
|
37
|
+
nextConfig.env = __assign(__assign({}, nextConfig.env), { amplifyConfig: JSON.stringify(amplifyConfig) });
|
|
27
38
|
return nextConfig;
|
|
28
39
|
};
|
|
29
40
|
//# sourceMappingURL=withAmplify.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withAmplify.js","sourceRoot":"","sources":["../src/withAmplify.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;AAKtC,oEAAoE;AACpE,2EAA2E;AAC3E,sCAAsC;AAEtC
|
|
1
|
+
{"version":3,"file":"withAmplify.js","sourceRoot":"","sources":["../src/withAmplify.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;;;;;;;;;;;AAKtC,oEAAoE;AACpE,2EAA2E;AAC3E,sCAAsC;AAEtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,IAAM,WAAW,GAAG,UAC1B,UAAsB,EACtB,aAA8B;IAE9B,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG,KACjB,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAC5C,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,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.957cda4.0+957cda4",
|
|
19
19
|
"jest-fetch-mock": "3.0.3",
|
|
20
20
|
"next": ">= 13.4.0 < 14.0.0",
|
|
21
21
|
"typescript": "5.1.6"
|
|
@@ -107,6 +107,6 @@
|
|
|
107
107
|
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
|
|
108
108
|
},
|
|
109
109
|
"typings": "./lib-esm/index.d.ts",
|
|
110
|
-
"version": "0.0.2-console-preview.
|
|
111
|
-
"gitHead": "
|
|
110
|
+
"version": "0.0.2-console-preview.957cda4.0+957cda4",
|
|
111
|
+
"gitHead": "957cda4161ffdf663890650e52d032f64197b67a"
|
|
112
112
|
}
|
|
@@ -27,12 +27,12 @@ export const runWithAmplifyServerContext: NextServer.RunOperationWithContext =
|
|
|
27
27
|
// context with token and credentials provider.
|
|
28
28
|
if (amplifyConfig.Auth) {
|
|
29
29
|
const keyValueStorage =
|
|
30
|
+
// When `null` is passed as the value of `nextServerContext`, opt-in
|
|
31
|
+
// unauthenticated role (primarily for static rendering). It's
|
|
32
|
+
// safe to use the singleton `MemoryKeyValueStorage` here, as the
|
|
33
|
+
// static rendering uses the same unauthenticated role cross-sever.
|
|
30
34
|
nextServerContext === null
|
|
31
|
-
?
|
|
32
|
-
// unauthenticated role (primarily for static rendering). It's
|
|
33
|
-
// safe to use the singleton `MemoryKeyValueStorage` here, as the
|
|
34
|
-
// static rendering uses the same unauthenticated role cross-sever.
|
|
35
|
-
MemoryKeyValueStorage
|
|
35
|
+
? MemoryKeyValueStorage
|
|
36
36
|
: createKeyValueStorageFromCookieStorageAdapter(
|
|
37
37
|
createCookieStorageAdapterFromNextServerContext(nextServerContext)
|
|
38
38
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { ResourcesConfig } from '
|
|
4
|
+
import { ResourcesConfig } from 'aws-amplify';
|
|
5
5
|
import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core';
|
|
6
6
|
|
|
7
7
|
export const getAmplifyConfig = (): ResourcesConfig => {
|
package/src/withAmplify.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { ResourcesConfig } from '
|
|
4
|
+
import { ResourcesConfig, parseAmplifyConfig } from 'aws-amplify';
|
|
5
5
|
import { NextConfig } from 'next';
|
|
6
6
|
|
|
7
7
|
// NOTE: this function is exported from the subpath `/with-amplify`.
|
|
@@ -10,8 +10,21 @@ import { NextConfig } from 'next';
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Merges the `amplifyConfig` into the `nextConfig.env`.
|
|
13
|
+
*
|
|
13
14
|
* @param nextConfig The next config for a Next.js app.
|
|
14
|
-
* @param amplifyConfig
|
|
15
|
+
* @param amplifyConfig The Amplify configuration.
|
|
16
|
+
*
|
|
17
|
+
* **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js`
|
|
18
|
+
* file, you need to use {@link parseAmplifyConfig} to reformat the configuration.
|
|
19
|
+
* E.g.
|
|
20
|
+
* ```javascript
|
|
21
|
+
* const { parseAmplifyConfig } = require('aws-amplify');
|
|
22
|
+
* const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify');
|
|
23
|
+
* const config = require('./src/aws-exports');
|
|
24
|
+
*
|
|
25
|
+
* const nextConfig = {};
|
|
26
|
+
* module.exports = withAmplify(nextConfig, parseAmplifyConfig(config));
|
|
27
|
+
* ```
|
|
15
28
|
* @returns The updated `nextConfig`.
|
|
16
29
|
*/
|
|
17
30
|
export const withAmplify = (
|
|
@@ -20,7 +33,6 @@ export const withAmplify = (
|
|
|
20
33
|
) => {
|
|
21
34
|
nextConfig.env = {
|
|
22
35
|
...nextConfig.env,
|
|
23
|
-
// TODO(Hui): follow up the validation of the amplifyConfig.
|
|
24
36
|
amplifyConfig: JSON.stringify(amplifyConfig),
|
|
25
37
|
};
|
|
26
38
|
|