nostr login fetch details and nip05
This commit is contained in:
@@ -196,6 +196,9 @@ class SessionService {
|
||||
// Set as current user
|
||||
_currentUser = user;
|
||||
|
||||
// Load preferred relays from NIP-05 if available
|
||||
await _loadPreferredRelaysIfAvailable();
|
||||
|
||||
return user;
|
||||
} catch (e) {
|
||||
throw SessionException('Failed to login with Nostr: $e');
|
||||
@@ -360,5 +363,46 @@ class SessionService {
|
||||
if (_currentUser == null) return null;
|
||||
return _userCacheDirs[_currentUser!.id];
|
||||
}
|
||||
|
||||
/// Loads preferred relays from NIP-05 if the current user has an active nip05.
|
||||
///
|
||||
/// This method checks if the logged-in user has a nip05 identifier and,
|
||||
/// if so, fetches preferred relays from the NIP-05 verification endpoint
|
||||
/// and adds them to the Nostr service relay list.
|
||||
///
|
||||
/// This is called automatically after Nostr login, but can also be called
|
||||
/// manually to refresh preferred relays.
|
||||
Future<void> loadPreferredRelaysIfAvailable() async {
|
||||
await _loadPreferredRelaysIfAvailable();
|
||||
}
|
||||
|
||||
/// Internal method to load preferred relays from NIP-05 if available.
|
||||
Future<void> _loadPreferredRelaysIfAvailable() async {
|
||||
if (_currentUser == null || _nostrService == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final profile = _currentUser!.nostrProfile;
|
||||
if (profile == null || profile.nip05 == null || profile.nip05!.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final nip05 = profile.nip05!;
|
||||
final publicKey = _currentUser!.id; // User ID is the public key for Nostr users
|
||||
|
||||
final addedCount = await _nostrService!.loadPreferredRelaysFromNip05(
|
||||
nip05,
|
||||
publicKey,
|
||||
);
|
||||
|
||||
if (addedCount > 0) {
|
||||
debugPrint('Loaded $addedCount preferred relay(s) from NIP-05: $nip05');
|
||||
}
|
||||
} catch (e) {
|
||||
// Log error but don't fail - offline-first behavior
|
||||
debugPrint('Warning: Failed to load preferred relays from NIP-05: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user