Skip to content

fix: honor target relay in profile sync with NIP-42 auth and fallback#4

Merged
derekross merged 10 commits into
derekross:mainfrom
advorzhak:check-target-relay-issue
Jun 14, 2026
Merged

fix: honor target relay in profile sync with NIP-42 auth and fallback#4
derekross merged 10 commits into
derekross:mainfrom
advorzhak:check-target-relay-issue

Conversation

@advorzhak

Copy link
Copy Markdown
Contributor

Fixes #3

Summary

This PR fixes a critical bug where the "Target Relay" selected by the user in the Profile Sync interface was being completely ignored. Events were instead being published to the app's default relay.

Changes Made

  • Exclusive Target Routing: Refactored useSyncProfile to exclusively use a dedicated NPool configured with an eventRouter that explicitly targets the user-selected targetRelay.
  • NIP-42 Authentication Support: Injected an auth callback into the NRelay1 instantiation. This automatically responds to AUTH challenges (kind 22242) using the current user's signer, enabling successful sync to paid or protected relays.
  • Graceful Fallback: Implemented a fallback mechanism. If the target relay fails, the system automatically attempts to publish to the default relay to prevent data loss.
  • Enhanced Logging: Added clear, prefixed console logs (📤 Publishing..., ✅ Successfully published..., ⚠️ TARGET relay failed...) to explicitly show which relay is receiving each event.
  • Comprehensive Unit Tests: Added a new test suite (useSyncProfile.test.tsx) covering:
    • Successful publishing to target relay
    • Fallback to default relay on target failure
    • Complete failure handling
    • NIP-42 AUTH callback triggering and correct event generation
    • Input validation (invalid URLs, empty events)

Validation

  • ✅ All new unit tests pass (6/6)
  • ✅ TypeScript compilation (tsc --noEmit) passes
  • ✅ Project build (npm run build) succeeds

kilo-code-bot Bot and others added 2 commits May 20, 2026 17:45
Include kind 10063 (BUD-03 user server list) in profile sync operations.
Users' preferred Blossom media servers are now fetched, displayed, and
synced alongside other profile metadata.

Closes derekross#1
- Previously, useSyncProfile attempted to publish via the global nostr pool first, ignoring the user-selected target relay.
- Updated to exclusively use a dedicated NPool configured with an eventRouter targeting the selected relay.
- Implemented NIP-42 AUTH callback support in NRelay1 to automatically authenticate with paid/protected relays.
- Added fallback logic to the default relay if the target relay fails.
- Added comprehensive unit tests for successful sync, fallback, failure, NIP-42 auth, and input validation.
- Enhanced logging to clearly indicate which relay is receiving each event.
@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@advorzhak is attempting to deploy a commit to the derekross' projects Team on Vercel.

A member of the Team first needs to authorize it.

@advorzhak advorzhak force-pushed the check-target-relay-issue branch from d395b64 to ad88381 Compare June 14, 2026 13:16
@derekross derekross merged commit 16756e4 into derekross:main Jun 14, 2026
1 check failed
@advorzhak advorzhak deleted the check-target-relay-issue branch June 14, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Target Relay is not honored during profile sync (publishes to default relay instead)

2 participants