web


git clone https://radroots.dev/git/web.git
Log | Files | Refs | Submodules | README | LICENSE

+layout.ts (861B)


      1 
      2 import { datastore, nostr_keys, route } from '$lib/utils/app';
      3 import { type AppData } from '$lib/utils/config';
      4 import { handle_err } from '@radroots/apps-lib';
      5 import type { LayoutLoad, LayoutLoadEvent } from '../$types';
      6 
      7 export type LayoutAppLoad = {
      8     public_key: string;
      9 } | undefined;
     10 
     11 export const load: LayoutLoad<LayoutAppLoad> = async (_: LayoutLoadEvent) => {
     12     try {
     13         await datastore.init();
     14         const ds_app_data = await datastore.get_obj<AppData>("app_data");
     15         if ("err" in ds_app_data) return void await route(`/setup`);
     16         const ks_active_key = await nostr_keys.read(ds_app_data.result.active_key);
     17         if ("err" in ks_active_key) return void await route(`/setup`);
     18         return {
     19             public_key: ds_app_data.result.active_key
     20         };
     21     } catch (e) {
     22         handle_err(e, `(app)load`);
     23     };
     24 };