mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2025-12-27 21:30:16 +00:00
🔒 Add Nostr authentication support with custom guard and user provider
🛠️ Integrate Nostr auth across relevant components and views 📦 Update config, routes, and service provider for Nostr auth
This commit is contained in:
55
app/Livewire/Traits/WithNostrAuth.php
Normal file
55
app/Livewire/Traits/WithNostrAuth.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Traits;
|
||||
|
||||
use App\Support\NostrAuth;
|
||||
use Livewire\Attributes\On;
|
||||
|
||||
trait WithNostrAuth
|
||||
{
|
||||
public ?string $currentPubkey = null;
|
||||
public ?object $currentPleb = null;
|
||||
public bool $isAllowed = false;
|
||||
public bool $canEdit = false;
|
||||
|
||||
#[On('nostrLoggedIn')]
|
||||
public function handleNostrLogin(string $pubkey): void
|
||||
{
|
||||
NostrAuth::login($pubkey);
|
||||
|
||||
$this->currentPubkey = $pubkey;
|
||||
$this->currentPleb = \App\Models\EinundzwanzigPleb::query()
|
||||
->where('pubkey', $pubkey)
|
||||
->first();
|
||||
|
||||
if ($this->currentPleb && in_array($this->currentPleb->npub, config('einundzwanzig.config.current_board'), true)) {
|
||||
$this->canEdit = true;
|
||||
}
|
||||
|
||||
$this->isAllowed = true;
|
||||
}
|
||||
|
||||
#[On('nostrLoggedOut')]
|
||||
public function handleNostrLogout(): void
|
||||
{
|
||||
NostrAuth::logout();
|
||||
|
||||
$this->isAllowed = false;
|
||||
$this->currentPubkey = null;
|
||||
$this->currentPleb = null;
|
||||
$this->canEdit = false;
|
||||
}
|
||||
|
||||
public function mountNostrAuth(): void
|
||||
{
|
||||
if ($user = NostrAuth::user()) {
|
||||
$this->currentPubkey = $user->getPubkey();
|
||||
$this->currentPleb = $user->getPleb();
|
||||
$this->isAllowed = true;
|
||||
|
||||
if ($this->currentPleb && in_array($this->currentPleb->npub, config('einundzwanzig.config.current_board'), true)) {
|
||||
$this->canEdit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user