fetchProfile() doesn't return NDKUserProfile on first load
On the first load, user.fetchProfile doesn't return NDKUserProfile, but an object which has pubkey, profile and created_at properties. On consecutive loads, it returns the NDKUserProfile correctly.
const user = ndk().getUser({pubkey: pubKeyHex})
console.log("Fetching profile for", pubKeyHex)
let profile = await user.fetchProfile({closeOnEose: false})
console.log("Profile fetched", JSON.stringify(profile), profile)
console.log("profile image", profile?.image)
if (profile && profile.image) {
console.log("Setting profile image", profile.image)
setImage(profile.image)
handleProfile(pubKeyHex, profile)
}
Output:
Fetching profile for 4523be58d395b1b196a9b8c82b038b6895cb02b683d0c253a955068dba1facd0
Avatar.tsx:41 Profile fetched {
"pubkey": "4523be58d395b1b196a9b8c82b038b6895cb02b683d0c253a955068dba1facd0",
"profile": {
"banner": "https://nostr.build/i/nostr.build_59dc3be449d722379b12c095566cf4aeafae9b437d3afaf356ffc69370e93cc7.jpg",
"website": "https://twitter.com/marttimalmi",
"nip05": "[email protected]",
"image": "https://cdn.nostr.build/i/8274ce86cc4477b80c8cad5ff4dfebe55f1223b3e35dfc10a1e19a67f29a8f8f.jpg",
"lud16": "[email protected]",
"about": "iris.to dev. 🇫🇮",
"name": "Martti Malmi",
"nip05valid": true
},
"createdAt": 1717145373722
}
Avatar.tsx:42 profile image undefined
NDK version:
nostr-dev-kit/ndk 2.8.2 nostr-dev-kit/ndk-cache-dexie 2.4.2
hey I ran into the same issue. I see in dev tools that event kind 0 gets fetched but in javascript the profile isn't loaded. I saw your comment and duplicated the line and voila, the profile is fetched.
Now, I would like at least try to fix that or debug whats going on. But I am not a frontend dev and struggling with npm stuff too much. How do you load your project with local lib (ndk repo in this case)? I added the path to my package.json:
but when running the app (in svelte), here is what I see:
I am trying a relative path too and I am sure the path is 100% correct. Could there be something I have to add to ndk library to make it available? I have no idea what is that main/module/exports thing.. I assume Pablo will be too busy with many other things these days, maybe we can find the solution for this and open a PR