11.0.5 • Published 2 years ago

@rill/session v11.0.5

Weekly downloads
12
License
MIT
Repository
github
Last release
2 years ago

Isomorphic session middleware that will provided consistent sessions from client to server. Sessions are instances of Receptacle, check out the docs for modifying the session.

Session storage on the server side is done by keyv and you can provide configuration via the cache option.

Installation

npm install @rill/session

Example

const app = require('rill')()

// Set up a session. (Defaults to in memory)
app.use(require('@rill/session')())

// Use the session.
app.use(({ session })=> {
  // Sessions are instances of a "Receptacle" cache.
  session.set('a', 1, { ttl: 1000 });
  session.get('a'); // 1
});

Options

{
  /**
   * Optional key used for the session id cookie and keyv namespace.
   */
  key: 'rill_session',
  /**
   * Optional key to use as the name of the session on the Rill context.
   * This allows for having multiple sessions (even with different adapters) all with different names.
   * By default they will all use the name 'session'.
   */
  name: 'mySession',
  /**
   * By default the session is shared with the browser and therefor public.
   * You can disable this by setting browser to false which will only make the session visible server side and disables the sync apis.
   */
  browser: true,
  /**
   * By default @rill/session will add an http header to preload the session in the browser.
   * This improves performance by fetching your javascript and the session in parallel in supported browsers.
   * You can disable this by setting preload to false which will instead fetch the session after the main javascript has loaded.
   */
  preload: true,
  /**
   * Passed to keyv, do not send this to client.
   * Mongo db example. (must have installed keyv-mongo).
   * Default is in memory.
   */
  cache: !process.browser && {
    uri: 'mongodb://user:pass@localhost:27017/dbname' // Default is in memory (see keyv uri).
  }
}

Implementation Details

Rill sessions work in both the client and server however only the initial session from the server with the user will be synced using an XHR request.

In the browser the initial session is loaded from the server via XHR and then stored in memory.


Contributions

  • Use npm test to run tests.

Please feel free to create a PR!

11.0.4

2 years ago

11.0.5

2 years ago

11.0.2

2 years ago

11.0.3

2 years ago

11.0.0

2 years ago

11.0.1

2 years ago

10.1.0

6 years ago

10.0.0

7 years ago

9.1.0

7 years ago

9.0.1

7 years ago

9.0.0

7 years ago

8.0.1

7 years ago

8.0.0

7 years ago

7.5.0

7 years ago

7.3.0

7 years ago

7.2.4

7 years ago

7.2.3

7 years ago

7.2.2

7 years ago

7.2.1

7 years ago

7.2.0

7 years ago

7.1.0

7 years ago

7.0.0

7 years ago

6.1.0

8 years ago

6.0.5

8 years ago

6.0.4

8 years ago

6.0.3

8 years ago

6.0.2

8 years ago

6.0.1

8 years ago

6.0.0

8 years ago

5.1.0

8 years ago

5.0.2

8 years ago

5.0.1

8 years ago

5.0.0

8 years ago

4.0.2

8 years ago

4.0.1

8 years ago

4.0.0

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.4.2

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.8.1

8 years ago

0.8.0

8 years ago

0.7.0

9 years ago

0.6.0

9 years ago

0.5.2

9 years ago

0.5.1

9 years ago

0.5.0

9 years ago

0.4.3

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.99

9 years ago

0.0.98

9 years ago

0.0.97

9 years ago

0.0.96

9 years ago

0.0.95

9 years ago

0.0.94

9 years ago

0.0.93

9 years ago

0.0.92

9 years ago

0.0.91

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago