mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2025-12-23 16:50: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:
41
app/Auth/NostrSessionGuard.php
Normal file
41
app/Auth/NostrSessionGuard.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Auth;
|
||||
|
||||
use Illuminate\Auth\SessionGuard;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
class NostrSessionGuard extends SessionGuard
|
||||
{
|
||||
public function loginByPubkey(string $pubkey): void
|
||||
{
|
||||
$user = new NostrUser($pubkey);
|
||||
|
||||
$this->updateSession($user->getAuthIdentifier());
|
||||
|
||||
$this->setUser($user);
|
||||
|
||||
$this->fireLoginEvent($user, false);
|
||||
}
|
||||
|
||||
protected function updateSession($id): void
|
||||
{
|
||||
$this->session->put($this->getName(), $id);
|
||||
$this->session->migrate(true);
|
||||
}
|
||||
|
||||
public function user(): ?Authenticatable
|
||||
{
|
||||
if ($this->user !== null) {
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
$id = $this->session->get($this->getName());
|
||||
|
||||
if ($id !== null) {
|
||||
$this->user = $this->provider->retrieveById($id);
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user