mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-17 12:24:24 +01:00
feat: create user store middleware
This commit is contained in:
22
src/middleware/userStore.ts
Normal file
22
src/middleware/userStore.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user