mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
21 lines
605 B
TypeScript
21 lines
605 B
TypeScript
import { MiddlewareHandler } from '@hono/hono';
|
|
import { NostrSigner, NStore } from '@nostrify/nostrify';
|
|
|
|
import { UserStore } from '@/storages/UserStore.ts';
|
|
import { Storages } from '@/storages.ts';
|
|
|
|
/** Store middleware. */
|
|
export const storeMiddleware: MiddlewareHandler<{ Variables: { signer?: NostrSigner; store: NStore } }> = async (
|
|
c,
|
|
next,
|
|
) => {
|
|
const pubkey = await c.get('signer')?.getPublicKey();
|
|
|
|
if (pubkey) {
|
|
const store = new UserStore(pubkey, await Storages.admin());
|
|
c.set('store', store);
|
|
} else {
|
|
c.set('store', await Storages.admin());
|
|
}
|
|
await next();
|
|
};
|