6

I have separate repositories for my shell & my microfrontends & I would like to share the auth service data between shell & microfrontends.

I have used below article "Step 5: Share a Library of Your Monorepo" to create the AuthService shared library, but since mine is not Monorepo I published the library into npm:

https://github.com/angular-architects/module-federation-plugin/blob/12.0.0/libs/mf/tutorial/tutorial.md

npm of my AuthLibrary: https://www.npmjs.com/package/@vijender1256/auth-lib

I installed my npm package into my shell & microfrontends. I am setting login value in the shell app and wanted to share the user info in several microfrontends, I would like to use this library for AuthService state management across shell & microfrontends.

shell webpack.config.js

const { shareAll, withModuleFederationPlugin } = require('@angular-architects/module-federation/webpack');

module.exports = withModuleFederationPlugin({

  shared: {
    ...shareAll({ singleton: true, strictVersion: true, eager: true, requiredVersion: 'auto' }),
    ...sharedMappings.getDescriptors()
  },
  sharedMappings: ['@vijender1256/auth-lib'],
});

Microfrontend webpack.config.js:

const { shareAll, withModuleFederationPlugin } = require('@angular-architects/module-federation/webpack');

module.exports = withModuleFederationPlugin({

  name: 'itemMfe',

  exposes: {
    './ItemModule': './src/app/item/item.module.ts'
  },

  shared: {
    ...shareAll({ singleton: true, strictVersion: true, eager: true, requiredVersion: 'auto' }),
    ...sharedMappings.getDescriptors()
  },
  sharedMappings: ['@vijender1256/auth-lib'],
});

When i set the value in the shell, I do not get the value in the microfront end, instead it is instantiating the AuthService again and I am losing the user data that is being set in Shell.

I looked into my network & I do not see my library loading intially, but when I got the microfrontend it loads the library, but it is of no use, i am unable to share the user data from shell to micro front end.

enter image description here

Any suggestions to share the state?

VR1256
  • 1,266
  • 4
  • 28
  • 56

0 Answers0