@velas/account-agent
Version:
sdk
34 lines (24 loc) • 850 B
JavaScript
/*
* Remove expired items from localstorage
*/
async function removeExpiredItems(next) {
await this.provider.storage.removeExpiredItems();
const keys = await this.provider.keyStorage.removeExpiredItems();
const sessions = await this.provider.Session.find();
const keys_with_account = [];
for (const key of Object.keys(keys)) {
if (keys[key].account) keys_with_account.push(key)
};
for (const session of sessions) {
if (!keys_with_account.includes(session.op_key)) {
await session.destroy();
};
};
for (const key_with_account of keys_with_account) {
if (!sessions.map(i => i.op_key).includes(key_with_account)) {
await this.provider.keyStorage.destroy(key_with_account);
};
};
await next();
};
export default removeExpiredItems;