I am facing the issue on how to share a keycloak instance between MF shared via vite-module-federation
.
For security and identity management, I use the keycloak
solution. For creation and sharing of microfrontends purposes, I use vite-module-federation
. One of the federated modules provides redux store
which allows to keep in sync all data shared between MFs. For API calls I use RTK Query. Below is the simplified structure of the application:
<HostApp>
<StoreProvider store={StoreMF.store}>
<HeaderMF />
<Footer MF />
</StoreProvider>
</HostApp>
I am currently facing a problem with how to share the Keycloak instance between MFs. The Keycloak object initialisation is on the HostApp
layer. I’ve read that class instances should not be stored in the redux store because class as itself breaks the immutability rule. For now I need to share data as token
and userId
to be able to make API calls independently in each MF. In the future I would like to be able to force a logout with keycloak.logout
and so on. This will probably require access to the keycloak instance. The question is, how should I share this object or its part to ensure that it is up to date and I do not create any vulnerability? Perhaps there is another approach that allows me to do this:
-
make API request independently in each MF
-
use a keycloak solution
-
take care of security
Thanks in advance for any help
Patryk Gajewski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.