useBunkerStore: fix parsing of saved connections

This commit is contained in:
Alex Gleason 2024-10-29 15:00:49 -05:00
parent 4d99a6d4f6
commit df9cc19714
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 4 additions and 3 deletions

View File

@ -1,4 +1,3 @@
import { NSchema as n } from '@nostrify/nostrify';
import { produce } from 'immer'; import { produce } from 'immer';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { z } from 'zod'; import { z } from 'zod';
@ -28,7 +27,7 @@ const connectionSchema = z.object({
pubkey: z.string(), pubkey: z.string(),
accessToken: z.string(), accessToken: z.string(),
authorizedPubkey: z.string(), authorizedPubkey: z.string(),
bunkerSeckey: n.bech32('nsec'), bunkerSeckey: z.custom<Uint8Array>((value) => value instanceof Uint8Array),
}); });
interface BunkerState { interface BunkerState {
@ -63,10 +62,12 @@ export const useBunkerStore = create<BunkerState>()(
name: 'soapbox:bunker', name: 'soapbox:bunker',
storage: { storage: {
getItem(name) { getItem(name) {
const value = localStorage.getItem(name);
const connections = jsonSchema(nsecReviver) const connections = jsonSchema(nsecReviver)
.pipe(filteredArray(connectionSchema)) .pipe(filteredArray(connectionSchema))
.catch([]) .catch([])
.parse(localStorage.getItem(name)); .parse(value);
return { state: { connections } }; return { state: { connections } };
}, },