mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2026-01-11 13:40:14 +00:00
🛠️ Simplify route definition and update JS for Nostr profile handling
This commit is contained in:
@@ -5,15 +5,43 @@ export default () => ({
|
||||
},
|
||||
|
||||
async openNostrLogin() {
|
||||
console.log('Starting Nostr login...');
|
||||
console.log('window.nostr available:', !!window.nostr);
|
||||
|
||||
const pubkey = await window.nostr.getPublicKey();
|
||||
console.log('Fetched pubkey:', pubkey);
|
||||
|
||||
// fetch profile from /api/nostr/profile/{publicKey}
|
||||
fetch('/api/nostr/profile/' + pubkey)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Profile fetched', data);
|
||||
// store the profile in AlpineJS store
|
||||
Alpine.store('nostr', {user: data});
|
||||
this.$dispatch('nostrLoggedIn', {pubkey: data.pubkey});
|
||||
const url = '/api/nostr/profile/' + pubkey;
|
||||
console.log('Fetching profile from:', url);
|
||||
|
||||
fetch(url)
|
||||
.then(response => {
|
||||
console.log('Response status:', response.status);
|
||||
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);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -470,8 +470,8 @@ $loadEvents = function () {
|
||||
<template x-if="$store.nostr.user">
|
||||
<div class="flex items">
|
||||
<img class="w-12 h-12 rounded-full"
|
||||
x-bind:src="$store.nostr.user.picture"
|
||||
alt="">
|
||||
x-bind:src="$store.nostr.user.picture || '{{ asset('apple-touch-icon.png') }}'"
|
||||
alt="Avatar">
|
||||
<div class="ml-4">
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user