diff --git a/packages/adapter-nextjs/__tests__/withAmplify.test.ts b/packages/adapter-nextjs/__tests__/withAmplify.test.ts index be6a522567c..4c050fb6d12 100644 --- a/packages/adapter-nextjs/__tests__/withAmplify.test.ts +++ b/packages/adapter-nextjs/__tests__/withAmplify.test.ts @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ResourcesConfig } from '@aws-amplify/core'; +import { ResourcesConfig } from 'aws-amplify'; import { withAmplify } from '../src/withAmplify'; const mockAmplifyConfig: ResourcesConfig = { @@ -16,7 +16,7 @@ const mockAmplifyConfig: ResourcesConfig = { S3: { bucket: 'bucket', region: 'us-east-1', - } + }, }, }; diff --git a/packages/adapter-nextjs/src/runWithAmplifyServerContext.ts b/packages/adapter-nextjs/src/runWithAmplifyServerContext.ts index f930fe24dcc..9e6d6e89110 100644 --- a/packages/adapter-nextjs/src/runWithAmplifyServerContext.ts +++ b/packages/adapter-nextjs/src/runWithAmplifyServerContext.ts @@ -27,12 +27,12 @@ export const runWithAmplifyServerContext: NextServer.RunOperationWithContext = // context with token and credentials provider. if (amplifyConfig.Auth) { const keyValueStorage = + // When `null` is passed as the value of `nextServerContext`, opt-in + // unauthenticated role (primarily for static rendering). It's + // safe to use the singleton `MemoryKeyValueStorage` here, as the + // static rendering uses the same unauthenticated role cross-sever. nextServerContext === null - ? // When `null` is passed as the value of `nextServerContext`, opt-in - // unauthenticated role (primarily for static rendering). It's - // safe to use the singleton `MemoryKeyValueStorage` here, as the - // static rendering uses the same unauthenticated role cross-sever. - MemoryKeyValueStorage + ? MemoryKeyValueStorage : createKeyValueStorageFromCookieStorageAdapter( createCookieStorageAdapterFromNextServerContext(nextServerContext) ); diff --git a/packages/adapter-nextjs/src/utils/getAmplifyConfig.ts b/packages/adapter-nextjs/src/utils/getAmplifyConfig.ts index ba907f018a5..b0697fdbfd0 100644 --- a/packages/adapter-nextjs/src/utils/getAmplifyConfig.ts +++ b/packages/adapter-nextjs/src/utils/getAmplifyConfig.ts @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ResourcesConfig } from '@aws-amplify/core'; +import { ResourcesConfig } from 'aws-amplify'; import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core'; export const getAmplifyConfig = (): ResourcesConfig => { diff --git a/packages/adapter-nextjs/src/withAmplify.ts b/packages/adapter-nextjs/src/withAmplify.ts index 4ba1728af2e..745b38f553e 100644 --- a/packages/adapter-nextjs/src/withAmplify.ts +++ b/packages/adapter-nextjs/src/withAmplify.ts @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ResourcesConfig } from '@aws-amplify/core'; +import { ResourcesConfig, parseAmplifyConfig } from 'aws-amplify'; import { NextConfig } from 'next'; // NOTE: this function is exported from the subpath `/with-amplify`. @@ -10,8 +10,21 @@ import { NextConfig } from 'next'; /** * Merges the `amplifyConfig` into the `nextConfig.env`. + * * @param nextConfig The next config for a Next.js app. - * @param amplifyConfig + * @param amplifyConfig The Amplify configuration. + * + * **NOTE**: If you are using Amplify CLI to generate the `aws-exports.js` + * file, you need to use {@link parseAmplifyConfig} to reformat the configuration. + * E.g. + * ```javascript + * const { parseAmplifyConfig } = require('aws-amplify'); + * const { withAmplify } = require('@aws-amplify/adapter-nextjs/with-amplify'); + * const config = require('./src/aws-exports'); + * + * const nextConfig = {}; + * module.exports = withAmplify(nextConfig, parseAmplifyConfig(config)); + * ``` * @returns The updated `nextConfig`. */ export const withAmplify = ( @@ -20,7 +33,6 @@ export const withAmplify = ( ) => { nextConfig.env = { ...nextConfig.env, - // TODO(Hui): follow up the validation of the amplifyConfig. amplifyConfig: JSON.stringify(amplifyConfig), };