You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

3 months ago
# Nano Session
3 months ago
3 months ago
Functions and Classes for handle session with [@nano/sqlite](https://git.node001.net/nano/sqlite) in [Bun](https://bun.sh/).
3 months ago
## API
### Session
3 months ago
Session Object has all Function to create, valid and remove Session. Sqlite can
be the same or a seperated database.
3 months ago
```
import { getOrCreateSqlite } from '@nano/sqlite'
3 months ago
import { getOrCreateSqlite } from '@nano/session'
const db = getOrCreateSqlite({ uri: ':memory:', create: true, readwrite: true })
3 months ago
const session = new Session(db)
```
#### create(userId: number, agent: string, language: string, ip = '')
Create a new Session for User. Agent and Language from User will be used to create a Hmac value in the DB. The IP is optional. If
one of these values are changed, the session is invalid. After Creating the session you get a Random Token, and the userId as
3 months ago
hash.
3 months ago
### get(userHash: string, token: string, agent: string, language: string, ip = '')
Get Session for User. If session has expired, the entry will be removed from Database.
### destroy(sessionId: number)
Remove single Session for User with id of Session.
### destroyAll(userId: number)
Remove all session for a User with UserId.