amplify-js icon indicating copy to clipboard operation
amplify-js copied to clipboard

Multiple Cognito Userpools in a Microfrontend application

Open mariasemionova opened this issue 1 year ago • 6 comments

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

mariasemionova avatar Sep 25 '24 15:09 mariasemionova