Skip to content

fix(aws-amplify): sync Cognito auth config and merge libraryOptions on reconfigure#14819

Open
ShrutiPundir17 wants to merge 2 commits into
aws-amplify:mainfrom
ShrutiPundir17:fix/init-singleton-auth-config-reconfigure
Open

fix(aws-amplify): sync Cognito auth config and merge libraryOptions on reconfigure#14819
ShrutiPundir17 wants to merge 2 commits into
aws-amplify:mainfrom
ShrutiPundir17:fix/init-singleton-auth-config-reconfigure

Conversation

@ShrutiPundir17
Copy link
Copy Markdown

@ShrutiPundir17 ShrutiPundir17 commented May 16, 2026

Solves issue : #14820

Description of changes

Problem

  1. Stale Cognito auth config on reconfigurecognitoUserPoolsTokenProvider.setAuthConfig() was only called on the first setup path. Later Amplify.configure calls that changed resourcesConfig.Auth did not refresh the token store. TokenStore builds storage keys from authConfig.Cognito.userPoolClientId, so tokens could use old keys.

  2. Dropped non-Auth libraryOptions when libraryOptions.Auth is set — Passing { Auth: { ... } } alone replaced the entire libraryOptions object in core (no merge), dropping options such as Storage from an earlier configure.

  3. Partial reconfigure without libraryOptions.Auth{ Auth: authLibraryOptions, ...libraryOptions } did not include prior Amplify.libraryOptions, so keys like Storage were omitted when only { ssr: true } was passed.

Solution (packages/aws-amplify/src/initSingleton.ts)

  • Merge ...Amplify.libraryOptions before applying new libraryOptions; pin Auth last when preserving default Cognito providers.
  • Call setAuthConfig(resolvedResourceConfig.Auth) when the default cognitoUserPoolsTokenProvider is in use on reconfigure paths.
  • Helpers: usesDefaultCognitoTokenProvider, syncDefaultCognitoAuthConfig.

Tests

  • __tests__/initSingleton.test.ts (mocked core) — 14 cases
  • __tests__/initSingleton.integration.test.ts (real core singleton) — 3 cases

Issue #, if available

No dedicated issue. Related configure behavior may overlap with PR #14815 (partial libraryOptions merge). Happy to rebase after #14815 merges if maintainers prefer a single PR.

Description of how you validated changes

cd packages/aws-amplify
..\..\node_modules\.bin\jest.cmd -w 1

Result: 51 tests passed (7 suites), including initSingleton.test.ts (14) and initSingleton.integration.test.ts (3).

Also ran @aws-amplify/core Singleton tests (12 passed) and @aws-amplify/auth TokenStore tests (13 passed). npm run build:esm-cjs in packages/aws-amplify succeeded.

Full monorepo yarn test and live Cognito sign-in were not run.

Checklist

  • PR description included
  • yarn test passes (full monorepo not run; aws-amplify Jest 51/51 locally)
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…n reconfigure

- Merge existing Amplify.libraryOptions when libraryOptions.Auth is provided so other categories are not dropped.

- Call setAuthConfig on the default Cognito token provider when resourcesConfig.Auth changes on reconfigure (partial libraryOptions or config-only).

- Merge prior libraryOptions on partial reconfigure without Auth override.

- Add regression tests for the above behaviors.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ShrutiPundir17 ShrutiPundir17 requested a review from a team as a code owner May 16, 2026 10:33
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 16, 2026

🦋 Changeset detected

Latest commit: f67c651

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
aws-amplify Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…e singleton

Validates Storage preservation and setAuthConfig on reconfigure without mocking @aws-amplify/core.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant