@hitchy/plugin-session

0.1.12 • Public • Published

@hitchy/plugin-session pipeline status

License

MIT

Usage

In your Hitchy-based application run this command

npm install --save @hitchy/plugin-session @hitchy/plugin-cookies

to install this plugin.

As illustrated above you are in charge of installing @hitchy/plugin-cookies which is a mandatory dependency for this plugin. So, if you get an error regarding some unmet dependency on a role cookies you might need to repeat this command exactly as given.

After restarting your Hitchy-based application it is discovering this plugin and instantly injecting policy for selecting server-side session by ID provided in cookie passed with every request. Usually, this is done by browsers implicitly. Any request missing cookie with session's ID causes start of another session and injecting instructions for saving cookie in response.

On server side the session is exposed in req.session. It consists of multiple properties:

  • user is provided to expose name and roles of some user. Managing current user is basically out of this plugin's scope. See hitchy-plugin-auth for that.
    • user.name is expected to be a string containing name of current user.
    • user.roles is a list of roles current user is authorized for.
  • data is an object prepared to hold arbitrary data.

Configuration

This plugin may be customized via section session of configuration. Currently, there is no actually supported parameter, but some preparation for selecting backend to use for persisting session data.

Create a file adjusting configuration section session in /config/session.js with content like this:

exports.session = {
	backend: ...
};

This example doesn't work due to omitting example for configuring backend which isn't supported, yet.

Notes

The current version doesn't support persistency, thus all sessions get lost on restarting Hitchy.

Readme

Keywords

none

Package Sidebar

Install

npm i @hitchy/plugin-session

Weekly Downloads

15

Version

0.1.12

License

MIT

Unpacked Size

10.8 kB

Total Files

8

Last publish

Collaborators

  • soletan
  • simon.friedo