Skip to content

Commit

Permalink
fix(adapter-nextjs): remove the constraint of calling createServerRun…
Browse files Browse the repository at this point in the history
…ner only once
  • Loading branch information
HuiSF committed Oct 31, 2023
1 parent cfbde4c commit 091f681
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
5 changes: 0 additions & 5 deletions packages/adapter-nextjs/__tests__/createServerRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ describe('createServerRunner', () => {
});
});

it('throws when get called more than once', () => {
createServerRunner({ config: mockAmplifyConfig });
expect(() => createServerRunner({ config: mockAmplifyConfig })).toThrow();
});

describe('runWithAmplifyServerContext', () => {
describe('when amplifyConfig.Auth is not defined', () => {
it('should call runWithAmplifyServerContextCore without Auth library options', () => {
Expand Down
11 changes: 1 addition & 10 deletions packages/adapter-nextjs/src/createServerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

import { ResourcesConfig } from 'aws-amplify';
import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core';
import { createRunWithAmplifyServerContext, getAmplifyConfig } from './utils';
import { NextServer } from './types';

let amplifyConfig: ResourcesConfig | undefined;

/**
* Creates the `runWithAmplifyServerContext` function to run Amplify server side APIs in an isolated request context.
*
Expand All @@ -30,13 +27,7 @@ let amplifyConfig: ResourcesConfig | undefined;
export const createServerRunner: NextServer.CreateServerRunner = ({
config,
}) => {
if (amplifyConfig) {
throw new AmplifyServerContextError({
message: '`createServerRunner` needs to be called only once.',
});
}

amplifyConfig = getAmplifyConfig(config);
const amplifyConfig = getAmplifyConfig(config);

return {
runWithAmplifyServerContext: createRunWithAmplifyServerContext({
Expand Down

0 comments on commit 091f681

Please sign in to comment.