Svelte load() + $ndk is kicking my ass.

- login asUser using any npub or NIP05 in URL

- without clearing authUser session (signed in via extension or bunker) if it exists

- instantiate asUser (if != authUser) and load profile on server side to generate and store QR code (image files) before page load

- store asUser $ndk, $user, and $qrcodes locally in PWA, to navigate entire app “as user” when route changes.

Do I instantiate $ndk separately for each user?

Do I instantiate on server and pass to browser?

Does $ndk need to pass updates to local $store … how does this work?

🫤

nostr:npub1l2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqutajft nostr:npub1zuuajd7u3sx8xu92yav9jwxpr839cs0kc3q6t56vd5u9q033xmhsk6c2uc … anybody?

Reply to this note

Please Login to reply.

Discussion

#asknostr

nostr is (mostly) client side, so you'd instantiate it always on the client side (you can't really instantiate something like NDK on the server and "pass" it to the end client)

It might make sense to have a look at the work nostr:npub18c556t7n8xa3df2q82rwxejfglw5przds7sqvefylzjh8tjne28qld0we7 is doing packaging NDK in a ready-made skeleton or have a look at production code in one of the multiple real-world reference implementations using NDK 😉

https://github.com/nostr-dev-kit/ndk/blob/master/REFERENCES.md

correct link:

https://github.com/nostr-dev-kit/ndk/blob/master/ndk/REFERENCES.md

and thank you dear Pablo.

nostr:npub1manlnflyzyjhgh970t8mmngrdytcp3jrmaa66u846ggg7t20cgqqvyn9tn you can also take a look at Nostr-Hooks (yes, it's a React lib, but you may still get some inspiration about how it's dealing with NDK)

https://github.com/ostyjs/nostr-hooks

Thank you all for your guidance. I’ll have more questions as I progress fwd on this social onboarding client for Nostr. So far … just a “follow me” QR code that opens in an exiting local client. Soon to be also “invite” QR codes (of course using nostr-ignition 😍 nostr:npub1zuuajd7u3sx8xu92yav9jwxpr839cs0kc3q6t56vd5u9q033xmhsk6c2uc ) for onboarding your fiends to nostr.

nostrmeet.me

https://github.com/nostrmeetme/nostrmeetme

I’m not sure I’m following completely but you can run NDK as a singleton in your app. It’s managing fetching and sending data. Then it’s up to you to manage that data (especially session data) in a way that is safe for users.

Happy to review code if it’s up somewhere.

That took up like ALL of my post Covid brain cells. For some reason I could wrap my head around how to get data dynamically in svelte. I tried every attempt possible and pulled my hair for days. Turns out good old fashioned fetch after all.

Now I have QR codes rendering on server side, fetched AFTER user data has loaded on client side.

https://nostrmeet.me/_@jeffg.fyi

Which means I can use actual images (data urls) instead of canvas to render QR codes. Which means … press and hold to save QR to device for printing or sharing on social. Whew.

Wow. Cool QRs!