mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2025-12-20 13:20: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:
61
app/Support/NostrAuth.php
Normal file
61
app/Support/NostrAuth.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Auth\NostrUser;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class NostrAuth
|
||||
{
|
||||
/**
|
||||
* Login a user by their Nostr pubkey
|
||||
*/
|
||||
public static function login(string $pubkey): void
|
||||
{
|
||||
Auth::guard('nostr')->loginByPubkey($pubkey);
|
||||
Session::regenerate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout the current Nostr user
|
||||
*/
|
||||
public static function logout(): void
|
||||
{
|
||||
if (Auth::guard('nostr')->check()) {
|
||||
Session::flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently authenticated Nostr user
|
||||
*/
|
||||
public static function user(): ?NostrUser
|
||||
{
|
||||
return Auth::guard('nostr')->user();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Nostr user is authenticated
|
||||
*/
|
||||
public static function check(): bool
|
||||
{
|
||||
return Auth::guard('nostr')->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current pubkey (convenience method)
|
||||
*/
|
||||
public static function pubkey(): ?string
|
||||
{
|
||||
return self::user()?->getPubkey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current pleb (convenience method)
|
||||
*/
|
||||
public static function pleb(): ?object
|
||||
{
|
||||
return self::user()?->getPleb();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user