@did-connect/storage
v2.2.4
Published
Storage interface for did-auth
Downloads
5,575
Readme
Introduction
Defines the interface for DID Connect Session Storage, basic APIs that a session storage includes:
async create(session, attrs)
, create a new session record, persist in storageasync read(session)
, read a session from storage,async update(session, updates)
, update session recordasync delete(session)
, remove a session record
Install
npm install @did-connect/storage
// or
yarn add @did-connect/storage
Usage
const { BaseStorage } = require('@did-connect/storage');
const keystone = require('keystone');
module.exports = class KeystoneStorage extends BaseStorage {
constructor() {
this.model = keystone.list('sessions').model;
}
create(sessionId, attrs) {
const LoginToken = this.model;
const item = new LoginToken({ sessionId, ...attrs });
return item.save();
}
read(sessionId) {
return this.model.findOne({ sessionId });
}
update(sessionId, updates) {
return this.model.findOneAndUpdate({ sessionId }, updates);
}
delete(sessionId) {
return this.model.remove({ sessionId });
}
};