Open Unemployed opened 1 month ago
Hello, @Unemployed and thank you for opening this issue. I'm marking this as a feature request at this time due to the cognitoUserPoolsTokenProvider
being a singleton that is not connected to Amplify.configure()
. This means that manual updates are needed every time when you're looking to change your config for Auth. The way you're currently working around this by calling Amplify.configure
again as needed to update the auth config used by the token provider is the only way to do this right now.
I'll review this with the team to see if there's a way we can resolve this and follow up with any additional questions we may have.
@Unemployed, I think we'll actually flip the labeling of this issue to a bug due to the exposed single for cognitoUserPoolsTokenProvider
being a signleton that cannot reflect changes to new config calls. If this was fixed, would this address the issue for you?
Thanks @cwomack, yes if cognitoUserPoolsTokenProvider
was able to update after Amplify.configure
changes that should fix the issue.
@Unemployed, appreciate the confirmation. We'll keep this issue updated with any further questions we have or progress as we make it.
I am sorry if it is out of scope of this thread. But I didn't find anything more related to my question: Is there a way to use a single "aws-amplify/auth" configuration across multiple microfrontend apps?
I have a monorepo (Turborepo managed with pnpm) where all authentication logic is centralized in the main app. The other apps function as subpaths of the main app, facilitated by Next.js rewrites (NextJS 14 App Router). However, when I navigate to a subapp, it seems that the "aws-amplify/auth" context is lost.
I'm trying to run Amplify.configure(amplify_outputs) with the same configuration in all subapps as early as possible (root layout). I was hoping this would allow it to recognize session data from Cognito cookies, which are accessible to the subapps.
However, when I call "fetchAuthSession()" from subapp, it returns no data, indicating that the user is unauthenticated. While same call from the main app will return session data.
Does anyone know of an example of a similar setup or have suggestions on how to resolve this?
P.S. I also update Amplify.config after initialisation: each time before login. My users are located in different user pools. I check by email which UserPoll to use. So I also encountered same issue that Cookies ClientID wasn't updated.
@mariasemionova, it sounds like you're also commenting on this thread because you're trying to use multiple user pools and having issues with this when calling Amplify.configure()
. Can you help me understand the use case behind why you're needing multiple user pools?
Also, there may be some value in seeing the convo this related issue and comment of #12986.
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth, storage
Backend
None
Environment information
Describe the bug
cognitoUserPoolsTokenProvider
does not respect Cognito changes toAmplify.configure(...)
after initial load, and writes to local storage using outdated config keys. Requires a call tocognitoUserPoolsTokenProvider.authTokenStore.setAuthConfig
to update the config.From:
import { cognitoUserPoolsTokenProvider } from "aws-amplify/auth/cognito";
Expected behavior
I expected
<Authenticator>
UI component would always persist token details using the last set amplify config, even if the component is re-rendered.Reproduction steps
Using SPA, page is not refreshed until step 7:
Amplify.configure(config1);
<Authenticator>
componentsignOut
fromuseAuthenticator((x) => [x.signOut]);
Amplify.configure(config2);
<Authenticator>
UI componentCognitoIdentityServiceProvider.OLD_CLIENT_ID.x.clockDrift...
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
Config1:
Config2:
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
Update config when clicking either radio button:
Auth flow is
USER_SRP_AUTH
for both configs.