https://github.com/trekjs/sessions
Sessions middleware
https://github.com/trekjs/sessions
Last synced: about 1 month ago
JSON representation
Sessions middleware
- Host: GitHub
- URL: https://github.com/trekjs/sessions
- Owner: trekjs
- License: mit
- Created: 2016-10-08T15:40:57.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-08T00:29:16.000Z (almost 8 years ago)
- Last Synced: 2025-04-20T02:33:43.904Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 179 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sessions
Sessions middleware.
## Installation
```
$ npm install trek-sessions --save
```## Examples
```js
const Engine = require('trek-engine')
const sessions = require('trek-sessions')async function start (port = 3000) {
const app = new Engine()
app.config.set('cookie', {
keys: ['trek', 'engine']
})app.use(sessions({
cookie: {
signed: false,
maxAge: 60 * 1000 // 1 minutes
}
}))app.use((ctx, next) => {
ctx.res.body = ctx.session
})app.run(port)
}start().catch(console.error)
```## API
### `Sessions`
### `Store`
> Map like
```js
const store = new Store(provider, {
expires: 86400,
prefix: 'trek:sess:'
})
```* `provider`
The `sessions` are storing on the `provider`.
* `previx(sid)`
Adds a prefix to `sid`.
* `async clear()`
Removes all sessions.
* `async delete(sid)`
Removes a `session` by the `sid`.
* `async has(sid)`
Returns a boolean asserting whether a `session` has been associated to the `sid` in the `store` or not.
* `async get(sid)`
Returns the `session` associated to the `sid`, or `undefined` if there is none.
* `async set(sid, sess)`
Sets the `session` for the `sid` in the store.
### `Provider`
## Badges
[](https://travis-ci.org/trekjs/sessions)
[](https://codecov.io/gh/trekjs/sessions)
[](./LICENSE)---
> [fundon.me](https://fundon.me) ·
> GitHub [@fundon](https://github.com/fundon) ·
> Twitter [@_fundon](https://twitter.com/_fundon)