Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/hooks/useConnectedIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,33 @@ export function useConnectedIdentity() {
let cancelled = false;
fetchingRef.current = true;

// Register user in DB (fire-and-forget)
if (registeredRef.current !== address) {
registeredRef.current = address;
fetch("/api/user/register-by-wallet", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ walletAddress: address }),
}).catch(() => {
// Non-fatal — profile will still work from live API
});
}
const addr = address; // capture for closure type narrowing
async function init() {
// Step 1: Register (populates DB with SteemHunt/Neynar data)
if (registeredRef.current !== addr) {
registeredRef.current = addr;
try {
await fetch("/api/user/register-by-wallet", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ walletAddress: addr }),
});
} catch {
// Non-fatal — profile will still work from live API
}
}

getFarcasterProfile(address).then((p) => {
// Step 2: Now fetch profile (DB is populated, no external API needed)
if (!cancelled) {
setResult({ profile: p, resolvedFor: address });
fetchingRef.current = false;
const p = await getFarcasterProfile(addr);
if (!cancelled) {
setResult({ profile: p, resolvedFor: addr });
fetchingRef.current = false;
}
}
});
}

init();
return () => {
cancelled = true;
};
Expand Down
Loading