Skip to content

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

Merged
bobbor merged 5 commits into
aws-amplify:mainfrom
ShrutiPundir17:fix/init-singleton-auth-config-reconfigure
Jun 4, 2026
Merged

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

Conversation

@ShrutiPundir17

@ShrutiPundir17 ShrutiPundir17 commented May 16, 2026

Copy link
Copy Markdown
Contributor

Solves issue : #14820

Description of changes

When DefaultAmplify.configure runs again with a new resourcesConfig.Auth but without libraryOptions.Auth, the default cognitoUserPoolsTokenProvider was not always refreshed. TokenStore storage keys depend on authConfig.Cognito.userPoolClientId, so tokens could read/write under stale keys after reconfigure (related to #13707).

Change (packages/aws-amplify/src/initSingleton.ts):

Pass-through to core when !resolvedResourceConfig.Auth or libraryOptions?.Auth is provided (caller owns Auth wiring).
Singleton-managed path (Auth in config, no libraryOptions.Auth): on every configure/reconfigure:
cognitoUserPoolsTokenProvider.setAuthConfig(resolvedResourceConfig.Auth)
cognitoUserPoolsTokenProvider.setKeyValueStorage(...) (SSR-aware: cookies vs defaultStorage)
Amplify.configure with default token + credentials providers
Out of scope: merging libraryOptions across configure calls (discussed on #14820; tracked separately in #14815 / #14816).

Issue #, if available
Fixes #14820
Related: #13707, #14815, #14816

Description of how you validated changes
cd packages/aws-amplify
....\node_modules.bin\jest.cmd initSingleton -w 1
Updated initSingleton.test.ts and initSingleton.integration.test.ts for pass-through vs refresh behavior.

Checklist

PR description included

yarn test passes (full monorepo — rely on CI)

Unit Tests are changed or added

Relevant documentation is changed or added
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

changeset-bot Bot commented May 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ae174f9

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>
ShrutiPundir17 and others added 3 commits May 24, 2026 21:34
Simplify initSingleton per maintainer feedback: pass-through when libraryOptions.Auth is set; otherwise always setAuthConfig and SSR-aware setKeyValueStorage. Removes libraryOptions merge from this PR.

Co-authored-by: Cursor <cursoragent@cursor.com>

@bobbor bobbor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR. approved

@ShrutiPundir17

ShrutiPundir17 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

thanks for the PR. approved

Thanks for approval @bobbor

One more review is required by other team member for merging, can you help with that.

@bobbor
bobbor merged commit 6f5a076 into aws-amplify:main Jun 4, 2026
41 checks passed
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.

fix(aws-amplify): refresh default Cognito auth config on DefaultAmplify reconfigure

3 participants