🛠️ Simplify route definition and update JS for Nostr profile handling

This commit is contained in:
HolgerHatGarKeineNode
2026-01-06 19:57:43 +01:00
parent 772853dc61
commit 5783445b68
7 changed files with 50 additions and 14 deletions

View File

@@ -24,8 +24,14 @@ class GetProfile extends Controller
'npub' => (new Key)->convertPublicKeyToBech32($key), 'npub' => (new Key)->convertPublicKeyToBech32($key),
]); ]);
return Profile::query() $profile = Profile::query()
->where('pubkey', $key) ->where('pubkey', $key)
->first(); ->first();
if (!$profile) {
return response()->json(['message' => 'Profile not found'], 200);
}
return $profile;
} }
} }

View File

@@ -40,11 +40,10 @@ trait NostrFetcherTrait
$requestMessage = new RequestMessage($subscriptionId, $filters); $requestMessage = new RequestMessage($subscriptionId, $filters);
$relayUrls = [ $relayUrls = [
'wss://relay.nostr.band', 'wss://relay.primal.net',
'wss://purplepag.es', 'wss://purplepag.es',
'wss://nostr.wine', 'wss://nostr.wine',
'wss://relay.damus.io', 'wss://relay.damus.io',
'wss://nostr.einundzwanzig.space',
]; ];
$data = null; $data = null;

File diff suppressed because one or more lines are too long

View File

@@ -5,15 +5,43 @@ export default () => ({
}, },
async openNostrLogin() { async openNostrLogin() {
console.log('Starting Nostr login...');
console.log('window.nostr available:', !!window.nostr);
const pubkey = await window.nostr.getPublicKey(); const pubkey = await window.nostr.getPublicKey();
console.log('Fetched pubkey:', pubkey);
// fetch profile from /api/nostr/profile/{publicKey} // fetch profile from /api/nostr/profile/{publicKey}
fetch('/api/nostr/profile/' + pubkey) const url = '/api/nostr/profile/' + pubkey;
.then(response => response.json()) console.log('Fetching profile from:', url);
.then(data => {
console.log('Profile fetched', data); fetch(url)
// store the profile in AlpineJS store .then(response => {
Alpine.store('nostr', {user: data}); console.log('Response status:', response.status);
this.$dispatch('nostrLoggedIn', {pubkey: data.pubkey}); console.log('Response ok:', response.ok);
console.log('Response headers:', response.headers);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.text();
})
.then(text => {
console.log('Response text:', text);
try {
const data = JSON.parse(text);
console.log('Profile fetched', data);
// store the profile in AlpineJS store
Alpine.store('nostr', {user: data});
this.$dispatch('nostrLoggedIn', {pubkey: pubkey});
} catch (e) {
console.error('JSON parse error:', e);
throw e;
}
})
.catch(error => {
console.error('Error during Nostr login:', error);
}); });
}, },

View File

@@ -470,8 +470,8 @@ $loadEvents = function () {
<template x-if="$store.nostr.user"> <template x-if="$store.nostr.user">
<div class="flex items"> <div class="flex items">
<img class="w-12 h-12 rounded-full" <img class="w-12 h-12 rounded-full"
x-bind:src="$store.nostr.user.picture" x-bind:src="$store.nostr.user.picture || '{{ asset('apple-touch-icon.png') }}'"
alt=""> alt="Avatar">
<div class="ml-4"> <div class="ml-4">
<h3 class="w-48 sm:w-full truncate text-lg leading-snug text-[#1B1B1B] dark:text-gray-100 font-bold" <h3 class="w-48 sm:w-full truncate text-lg leading-snug text-[#1B1B1B] dark:text-gray-100 font-bold"
x-text="$store.nostr.user.display_name"></h3> x-text="$store.nostr.user.display_name"></h3>

View File

@@ -1,5 +1,6 @@
<?php <?php
use App\Http\Controllers\Api\Nostr\GetProfile;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get('/nostr/profile/{key}', \App\Http\Controllers\Api\Nostr\GetProfile::class); Route::get('/nostr/profile/{key}', GetProfile::class);

View File

@@ -1,6 +1,8 @@
<?php <?php
use App\Console\Commands\Nostr\SyncProfiles;
use Illuminate\Support\Facades\Schedule; use Illuminate\Support\Facades\Schedule;
Schedule::command('backup:clean')->daily()->at('01:00'); Schedule::command('backup:clean')->daily()->at('01:00');
Schedule::command('backup:run')->daily()->at('01:30'); Schedule::command('backup:run')->daily()->at('01:30');
Schedule::command(SyncProfiles::class)->daily()->at('00:30');