@mashroom/mashroom-session

2.6.0 • Public • Published

Mashroom Session

Plugin for Mashroom Server, a Microfrontend Integration Platform.

This plugin adds Express session as middleware.

Usage

If node_modules/@mashroom is configured as plugin path just add @mashroom/mashroom-session as dependency.

You can override the default config in your Mashroom config file like this:

{
    "plugins": {
        "Mashroom Session Middleware": {
            "order": -100,
            "provider": "Mashroom Session Filestore Provider",
            "session": {
                "secret": "EWhQ5hvETGkqvPDA",
                "resave": false,
                "saveUninitialized": false,
                "cookie": {
                    "maxAge": 7200000,
                    "httpOnly": true,
                    "secure": false,
                    "sameSite": false
                }
            }
        }
    }
}
  • order: The middleware order (Default: -100)
  • provider: The plugin from type session-store-provider that implements the store (Default: memory)
  • session: The properties are just passed to express-session. See Express session for possible options.
    • cookie.maxAge: Max cookie age in ms, which should be the max expected session duration (Default 2h)

Security hints:

  • Change the default secret
  • You should consider setting cookie.sameSite to either "lax" or "strict" (CSRF protection).

Plugin Types

session-store-provider

This plugin type adds a session store that can be used by this plugin.

To register a custom session-store-provider plugin add this to package.json:

{
    "mashroom": {
        "plugins": [
            {
                "name": "My Session Provider",
                "type": "session-store-provider",
                "bootstrap": "./dist/mashroom-bootstrap.js",
                "defaultConfig": {
                    "myProperty": "test"
                }
            }
        ]
    }
}

The bootstrap returns the express session store (here for example the file store):

import sessionFileStore from 'session-file-store';

import type {MashroomSessionStoreProviderPluginBootstrapFunction} from '@mashroom/mashroom-session/type-definitions';

const bootstrap: MashroomSessionStoreProviderPluginBootstrapFunction = async (pluginName, pluginConfig, pluginContextHolder, expressSession) => {
    const options = {...pluginConfig};
    const FileStore = sessionFileStore(expressSession);
    return new FileStore(options);
};

export default bootstrap;

Readme

Keywords

none

Package Sidebar

Install

npm i @mashroom/mashroom-session

Weekly Downloads

50

Version

2.6.0

License

MIT

Unpacked Size

16 kB

Total Files

14

Last publish

Collaborators

  • jkofler