@aws-amplify/adapter-nextjs 0.0.2-console-preview.1053355.0 → 0.0.2-console-preview.d7e0545.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.
@@ -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 = nextServerContext === null
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
- core_1.MemoryKeyValueStorage
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,GACpB,iBAAiB,KAAK,IAAI;oBACzB,CAAC,CAAC,oEAAoE;wBACpE,8DAA8D;wBAC9D,iEAAiE;wBACjE,mEAAmE;wBACnE,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
+ {"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 '@aws-amplify/core';
1
+ import { ResourcesConfig } from 'aws-amplify';
2
2
  export declare const getAmplifyConfig: () => ResourcesConfig;
@@ -1,11 +1,23 @@
1
1
  "use strict";
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
4
7
  Object.defineProperty(exports, "__esModule", { value: true });
5
8
  exports.getAmplifyConfig = void 0;
6
9
  var adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
10
+ var config_1 = __importDefault(require("next/config"));
7
11
  var getAmplifyConfig = function () {
8
12
  var configStr = process.env.amplifyConfig;
13
+ // With a Next.js app that uses the Pages Router, the key-value pairs
14
+ // listed under the `env` field in the `next.config.js` is not accessible
15
+ // via process.env.<key> at some occasion. Using the following as a fallback
16
+ // See: https://github.com/vercel/next.js/issues/39299
17
+ if (!configStr) {
18
+ var serverRuntimeConfig = (0, config_1.default)().serverRuntimeConfig;
19
+ configStr = serverRuntimeConfig === null || serverRuntimeConfig === void 0 ? void 0 : serverRuntimeConfig.amplifyConfig;
20
+ }
9
21
  if (!configStr) {
10
22
  throw new adapter_core_1.AmplifyServerContextError({
11
23
  message: 'Amplify configuration is missing from `process.env`.',
@@ -1 +1 @@
1
- {"version":3,"file":"getAmplifyConfig.js","sourceRoot":"","sources":["../../src/utils/getAmplifyConfig.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAGtC,yEAAqF;AAE9E,IAAM,gBAAgB,GAAG;IAC/B,IAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAE5C,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,IAAI,wCAAyB,CAAC;YACnC,OAAO,EAAE,sDAAsD;YAC/D,kBAAkB,EACjB,gEAAgE;SACjE,CAAC,CAAC;KACH;IAED,IAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE3C,gEAAgE;IAChE,OAAO,YAAY,CAAC;AACrB,CAAC,CAAC;AAfW,QAAA,gBAAgB,oBAe3B"}
1
+ {"version":3,"file":"getAmplifyConfig.js","sourceRoot":"","sources":["../../src/utils/getAmplifyConfig.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;;;;AAGtC,yEAAqF;AACrF,uDAAoC;AAE7B,IAAM,gBAAgB,GAAG;IAC/B,IAAI,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAE1C,qEAAqE;IACrE,yEAAyE;IACzE,4EAA4E;IAC5E,sDAAsD;IACtD,IAAI,CAAC,SAAS,EAAE;QACP,IAAA,mBAAmB,GAAK,IAAA,gBAAS,GAAE,oBAAhB,CAAiB;QAC5C,SAAS,GAAG,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,aAAa,CAAC;KAC/C;IAED,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,IAAI,wCAAyB,CAAC;YACnC,OAAO,EAAE,sDAAsD;YAC/D,kBAAkB,EACjB,gEAAgE;SACjE,CAAC,CAAC;KACH;IAED,IAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE3C,gEAAgE;IAChE,OAAO,YAAY,CAAC;AACrB,CAAC,CAAC;AAxBW,QAAA,gBAAgB,oBAwB3B"}
@@ -1,9 +1,22 @@
1
- import { ResourcesConfig } from '@aws-amplify/core';
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;
@@ -19,14 +19,27 @@ 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
+ var configStr = JSON.stringify(amplifyConfig);
41
+ nextConfig.env = __assign(__assign({}, nextConfig.env), { amplifyConfig: configStr });
42
+ nextConfig.serverRuntimeConfig = __assign(__assign({}, nextConfig.serverRuntimeConfig), { amplifyConfig: configStr });
30
43
  return nextConfig;
31
44
  };
32
45
  exports.withAmplify = withAmplify;
@@ -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;;;;;GAKG;AACI,IAAM,WAAW,GAAG,UAC1B,UAAsB,EACtB,aAA8B;IAE9B,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG;QACjB,4DAA4D;QAC5D,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAC5C,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAXW,QAAA,WAAW,eAWtB"}
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,IAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAChD,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG,KACjB,aAAa,EAAE,SAAS,GACxB,CAAC;IAEF,UAAU,CAAC,mBAAmB,yBAC1B,UAAU,CAAC,mBAAmB,KACjC,aAAa,EAAE,SAAS,GACxB,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAhBW,QAAA,WAAW,eAgBtB"}
@@ -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 = nextServerContext === null
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
- MemoryKeyValueStorage
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,GACpB,iBAAiB,KAAK,IAAI;oBACzB,CAAC,CAAC,oEAAoE;wBACpE,8DAA8D;wBAC9D,iEAAiE;wBACjE,mEAAmE;wBACnE,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
+ {"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 '@aws-amplify/core';
1
+ import { ResourcesConfig } from 'aws-amplify';
2
2
  export declare const getAmplifyConfig: () => ResourcesConfig;
@@ -1,8 +1,17 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core';
4
+ import getConfig from 'next/config';
4
5
  export var getAmplifyConfig = function () {
5
6
  var configStr = process.env.amplifyConfig;
7
+ // With a Next.js app that uses the Pages Router, the key-value pairs
8
+ // listed under the `env` field in the `next.config.js` is not accessible
9
+ // via process.env.<key> at some occasion. Using the following as a fallback
10
+ // See: https://github.com/vercel/next.js/issues/39299
11
+ if (!configStr) {
12
+ var serverRuntimeConfig = getConfig().serverRuntimeConfig;
13
+ configStr = serverRuntimeConfig === null || serverRuntimeConfig === void 0 ? void 0 : serverRuntimeConfig.amplifyConfig;
14
+ }
6
15
  if (!configStr) {
7
16
  throw new AmplifyServerContextError({
8
17
  message: 'Amplify configuration is missing from `process.env`.',
@@ -1 +1 @@
1
- {"version":3,"file":"getAmplifyConfig.js","sourceRoot":"","sources":["../../src/utils/getAmplifyConfig.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AAErF,MAAM,CAAC,IAAM,gBAAgB,GAAG;IAC/B,IAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAE5C,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,IAAI,yBAAyB,CAAC;YACnC,OAAO,EAAE,sDAAsD;YAC/D,kBAAkB,EACjB,gEAAgE;SACjE,CAAC,CAAC;KACH;IAED,IAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE3C,gEAAgE;IAChE,OAAO,YAAY,CAAC;AACrB,CAAC,CAAC"}
1
+ {"version":3,"file":"getAmplifyConfig.js","sourceRoot":"","sources":["../../src/utils/getAmplifyConfig.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC,MAAM,CAAC,IAAM,gBAAgB,GAAG;IAC/B,IAAI,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAE1C,qEAAqE;IACrE,yEAAyE;IACzE,4EAA4E;IAC5E,sDAAsD;IACtD,IAAI,CAAC,SAAS,EAAE;QACP,IAAA,mBAAmB,GAAK,SAAS,EAAE,oBAAhB,CAAiB;QAC5C,SAAS,GAAG,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,aAAa,CAAC;KAC/C;IAED,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,IAAI,yBAAyB,CAAC;YACnC,OAAO,EAAE,sDAAsD;YAC/D,kBAAkB,EACjB,gEAAgE;SACjE,CAAC,CAAC;KACH;IAED,IAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAE3C,gEAAgE;IAChE,OAAO,YAAY,CAAC;AACrB,CAAC,CAAC"}
@@ -1,9 +1,22 @@
1
- import { ResourcesConfig } from '@aws-amplify/core';
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;
@@ -16,14 +16,27 @@ 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
+ var configStr = JSON.stringify(amplifyConfig);
38
+ nextConfig.env = __assign(__assign({}, nextConfig.env), { amplifyConfig: configStr });
39
+ nextConfig.serverRuntimeConfig = __assign(__assign({}, nextConfig.serverRuntimeConfig), { amplifyConfig: configStr });
27
40
  return nextConfig;
28
41
  };
29
42
  //# 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;;;;;GAKG;AACH,MAAM,CAAC,IAAM,WAAW,GAAG,UAC1B,UAAsB,EACtB,aAA8B;IAE9B,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG;QACjB,4DAA4D;QAC5D,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAC5C,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC"}
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,IAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAChD,UAAU,CAAC,GAAG,yBACV,UAAU,CAAC,GAAG,KACjB,aAAa,EAAE,SAAS,GACxB,CAAC;IAEF,UAAU,CAAC,mBAAmB,yBAC1B,UAAU,CAAC,mBAAmB,KACjC,aAAa,EAAE,SAAS,GACxB,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.1053355.0+1053355",
18
+ "aws-amplify": "6.0.1-console-preview.d7e0545.0+d7e0545",
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.1053355.0+1053355",
111
- "gitHead": "1053355d0160296ba83ed4ae1b4f8cf759717f71"
110
+ "version": "0.0.2-console-preview.d7e0545.0+d7e0545",
111
+ "gitHead": "d7e0545d6fd84eb0e3a27b3cefbab5d2a4277c45"
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
- ? // When `null` is passed as the value of `nextServerContext`, opt-in
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,11 +1,21 @@
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 '@aws-amplify/core';
4
+ import { ResourcesConfig } from 'aws-amplify';
5
5
  import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core';
6
+ import getConfig from 'next/config';
6
7
 
7
8
  export const getAmplifyConfig = (): ResourcesConfig => {
8
- const configStr = process.env.amplifyConfig;
9
+ let configStr = process.env.amplifyConfig;
10
+
11
+ // With a Next.js app that uses the Pages Router, the key-value pairs
12
+ // listed under the `env` field in the `next.config.js` is not accessible
13
+ // via process.env.<key> at some occasion. Using the following as a fallback
14
+ // See: https://github.com/vercel/next.js/issues/39299
15
+ if (!configStr) {
16
+ const { serverRuntimeConfig } = getConfig();
17
+ configStr = serverRuntimeConfig?.amplifyConfig;
18
+ }
9
19
 
10
20
  if (!configStr) {
11
21
  throw new AmplifyServerContextError({
@@ -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 '@aws-amplify/core';
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,18 +10,36 @@ 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 = (
18
31
  nextConfig: NextConfig,
19
32
  amplifyConfig: ResourcesConfig
20
33
  ) => {
34
+ const configStr = JSON.stringify(amplifyConfig);
21
35
  nextConfig.env = {
22
36
  ...nextConfig.env,
23
- // TODO(Hui): follow up the validation of the amplifyConfig.
24
- amplifyConfig: JSON.stringify(amplifyConfig),
37
+ amplifyConfig: configStr,
38
+ };
39
+
40
+ nextConfig.serverRuntimeConfig = {
41
+ ...nextConfig.serverRuntimeConfig,
42
+ amplifyConfig: configStr,
25
43
  };
26
44
 
27
45
  return nextConfig;