feat: create user store middleware

This commit is contained in:
P. Reis 2024-04-27 17:00:03 -03:00
parent 606ab58c0a
commit 7b864482bf
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
import { AppMiddleware } from '@/app.ts';
import { UserStore } from '@/storages/UserStore.ts';
import { eventsDB } from '@/storages.ts';
import { HTTPException } from 'hono';
/** User Store middleware.
* Throw a 500 if can't set the `userStore` */
const setUserStore: AppMiddleware = async (c, next) => {
const pubkey = c.get('pubkey') as string;
try {
const store = new UserStore(pubkey, eventsDB);
c.set('userStore', store);
} catch (e) {
console.log(e);
throw new HTTPException(500);
}
await next();
};
export { setUserStore };