fix(aws-amplify): sync Cognito auth config and merge libraryOptions on reconfigure#14819
Open
ShrutiPundir17 wants to merge 2 commits into
Open
Conversation
…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>
🦋 Changeset detectedLatest commit: f67c651 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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>
3 tasks
4d253c1 to
f67c651
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solves issue : #14820
Description of changes
Problem
Stale Cognito auth config on reconfigure —
cognitoUserPoolsTokenProvider.setAuthConfig()was only called on the first setup path. LaterAmplify.configurecalls that changedresourcesConfig.Authdid not refresh the token store.TokenStorebuilds storage keys fromauthConfig.Cognito.userPoolClientId, so tokens could use old keys.Dropped non-Auth
libraryOptionswhenlibraryOptions.Authis set — Passing{ Auth: { ... } }alone replaced the entirelibraryOptionsobject in core (no merge), dropping options such asStoragefrom an earlier configure.Partial reconfigure without
libraryOptions.Auth—{ Auth: authLibraryOptions, ...libraryOptions }did not include priorAmplify.libraryOptions, so keys likeStoragewere omitted when only{ ssr: true }was passed.Solution (
packages/aws-amplify/src/initSingleton.ts)...Amplify.libraryOptionsbefore applying newlibraryOptions; pinAuthlast when preserving default Cognito providers.setAuthConfig(resolvedResourceConfig.Auth)when the defaultcognitoUserPoolsTokenProvideris in use on reconfigure paths.usesDefaultCognitoTokenProvider,syncDefaultCognitoAuthConfig.Tests
__tests__/initSingleton.test.ts(mocked core) — 14 cases__tests__/initSingleton.integration.test.ts(real core singleton) — 3 casesIssue #, if available
No dedicated issue. Related configure behavior may overlap with PR #14815 (partial
libraryOptionsmerge). Happy to rebase after #14815 merges if maintainers prefer a single PR.Description of how you validated changes
Result: 51 tests passed (7 suites), including
initSingleton.test.ts(14) andinitSingleton.integration.test.ts(3).Also ran
@aws-amplify/coreSingleton tests (12 passed) and@aws-amplify/authTokenStore tests (13 passed).npm run build:esm-cjsinpackages/aws-amplifysucceeded.Full monorepo
yarn testand live Cognito sign-in were not run.Checklist
yarn testpasses (full monorepo not run; aws-amplify Jest 51/51 locally)Checklist for repo maintainers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.