Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Cognito Userpools in a Microfrontend application #13850

Open
2 tasks
mariasemionova opened this issue Sep 25, 2024 · 2 comments
Open
2 tasks

Multiple Cognito Userpools in a Microfrontend application #13850

mariasemionova opened this issue Sep 25, 2024 · 2 comments
Assignees
Labels
Auth Related to Auth components/category pending-community-response Issue is pending a response from the author or community. question General question

Comments

@mariasemionova
Copy link

Is this related to a new or existing framework?

Next.js

Is this related to a new or existing API?

Authentication

Is this related to another service?

Cognito

Describe the feature you'd like to request

It would be nice to have a way to use a single "aws-amplify/auth" configuration across multiple microfrontend apps

App description:
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. Main app and all the subapps are using NextJS 14 with App Router.
All the Userpool creation logic is managed by backend with AWS API Gateway & Lambda functions.
Frontend is communicating with Backend through the API.

The problem:
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 "aws-amplify/auth", it returns no data, indicating that the user is unauthenticated.

Describe the solution you'd like

It would be nice to have ability to configure Amplify Auth within different parts of the Microfrontend apps, with ability to switch between multiple Cognito Userpools.

Describe alternatives you've considered

I tried to move my amplify and redux related configs to the shared location, but it doesn't help to fix the problem completely.

I am using multiple Cognito User pools, I am still facing an issue:
I am unable to change User pool ID and User pool Client ID, after initial Amplify.configure() call.
Seems like it is possible to configure it only once, and after it ignores all my attempts to update it with other values.
When I check Cognito cookies, I still see that they are linked to initial clientID despite, I tried to call Amplify.configure(updatedConfig).

This is also making the automatic token refresh working only for users from the initially configured User pool, not from the other ones.

Additional context

No response

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change
@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending a response from the Amplify team. labels Sep 25, 2024
@HuiSF HuiSF added question General question Auth Related to Auth components/category labels Sep 25, 2024
@github-actions github-actions bot removed the pending-triage Issue is pending triage label Sep 25, 2024
@HuiSF
Copy link
Member

HuiSF commented Sep 25, 2024

Hi @mariasemionova Thanks for opening this issue. For your use cases, you will need to ensure your micro front-end apps are sharing the same instances of the "Amplify singleton" to ensure the config you updated can be applied, this means all apps should use the same Amplify modules under the hood in a scope. Here's a previous investigation and its solution: #12986 (comment) you may refer to.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Sep 25, 2024
@HuiSF HuiSF added the pending-community-response Issue is pending a response from the author or community. label Sep 25, 2024
@cwomack cwomack self-assigned this Sep 25, 2024
@cwomack
Copy link
Member

cwomack commented Oct 1, 2024

@mariasemionova, wanted to ping you to see if you've had a chance to review @HuiSF's comment above. Let us know if you still have questions or need support from here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auth Related to Auth components/category pending-community-response Issue is pending a response from the author or community. question General question
Projects
None yet
Development

No branches or pull requests

3 participants