Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adebsalert/token-manager
Redis and JWT token based session manager
https://github.com/adebsalert/token-manager
Last synced: 24 days ago
JSON representation
Redis and JWT token based session manager
- Host: GitHub
- URL: https://github.com/adebsalert/token-manager
- Owner: AdebsAlert
- Created: 2019-09-17T12:45:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T18:40:49.000Z (almost 2 years ago)
- Last Synced: 2023-03-01T23:35:55.377Z (almost 2 years ago)
- Language: JavaScript
- Size: 128 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Softoken
`Redis` and `JWT` token based session manager.
## Usage
You will need [redis](http://redis.io) to use this package.
`npm install --save softoken`
### Configure
```javascript
var Softoken = require('softoken')
var session = new Softoken({
jwtSecret: 'secret',
[namespace]: 'ts',
[redis]: ioredisInstance,
[cleanupManual]: false
})```
### Create
```javascript
session.create({
uid: '1',
[ttl]: 7200,
[ip]: '127.0.0.1'
})
.then(function (jwtToken) { ... })
```### Get
```javascript
session.get('token')
.then(function (session) { ... })
```### Destroy
```javascript
session.destroy('token')
.then(function (isSuccess) { ... })
```### Extend
The second ttl parameter is optional.
```javascript
session.extend('token', 7200)
.then(function (expiresAt) { ... })
```### Get user's sessions
```javascript
session.getByUserId('1').then(function (sessions) { ... })
```### Destroy user's sessions
```javascript
session.destroyUser('1').then(function (isSuccess) { ... })
```### Cleanup
For manual session cleanup.
To clear only expired sessions
```javascript
session.cleanup().then(function () { ... })
```To clear every session
```javascript
session.cleanup(true).then(function () { ... })
```