Skip to content

fix(auth): update token provider auth config on reconfigure#14746

Open
anivar wants to merge 1 commit intoaws-amplify:mainfrom
anivar:fix/stale-auth-config-on-reconfigure
Open

fix(auth): update token provider auth config on reconfigure#14746
anivar wants to merge 1 commit intoaws-amplify:mainfrom
anivar:fix/stale-auth-config-on-reconfigure

Conversation

@anivar
Copy link
Contributor

@anivar anivar commented Mar 7, 2026

Description of changes

When Amplify.configure() is called multiple times to switch userPoolClientId (e.g. for multi-tenant apps), the cognitoUserPoolsTokenProvider was not updated with the new auth config on subsequent calls. This caused fetchAuthSession({ forceRefresh: true }) and internal token refresh to use the stale userPoolClientId, failing with NotAuthorizedException.

Root cause: In initSingleton.ts, cognitoUserPoolsTokenProvider.setAuthConfig() was only called on the first configure path (when !Amplify.libraryOptions.Auth). The two reconfigure paths — with and without libraryOptions — skipped it entirely.

Fix: Added cognitoUserPoolsTokenProvider.setAuthConfig(resolvedResourceConfig.Auth) to both reconfigure code paths. Two lines added, no structural changes.

Issue #, if available

Closes #14620

Description of how you validated changes

  • Updated 3 existing tests that incorrectly asserted setAuthConfig was NOT called on reconfigure
  • Added 1 new test verifying setAuthConfig is called with updated config when userPoolClientId changes
  • All 13 tests pass

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

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

When Amplify.configure() is called multiple times (e.g. to switch
userPoolClientId for multi-tenant apps), the cognitoUserPoolsTokenProvider
was not updated with the new auth config. This caused token refresh to
use the stale userPoolClientId, failing with NotAuthorizedException.

The fix adds cognitoUserPoolsTokenProvider.setAuthConfig() calls to the
two reconfigure code paths that were missing them in initSingleton.ts.

Closes aws-amplify#14620
@anivar anivar requested a review from a team as a code owner March 7, 2026 14:58
@changeset-bot
Copy link

changeset-bot bot commented Mar 7, 2026

🦋 Changeset detected

Latest commit: 12c8289

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

@anivar
Copy link
Contributor Author

anivar commented Mar 7, 2026

This also fixes #13707 (CognitoUserPoolsTokenProvider authTokenStore does not update keys with latest Auth config) — same root cause.

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.

Token refresh uses stale userPoolClientId after Amplify.configure() called multiple times

1 participant