authentikate/app/Livewire/ManageAuthenticationTokens.php
Javier Feliz 2e95a2a271
Some checks failed
linter / quality (push) Successful in 5m47s
tests / ci (push) Failing after 10m17s
Move tokens to their own page
2025-08-02 15:54:30 -04:00

45 lines
1.0 KiB
PHP

<?php
namespace App\Livewire;
use App\Models\AuthenticationToken;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Layout;
use Livewire\Component;
#[Layout('components.layouts.app')]
class ManageAuthenticationTokens extends Component
{
#[Computed]
public function tokens()
{
/** @var \App\Models\User $user */
$user = Auth::user();
return $user->tokens()
->with('application')
->orderBy('issued_at', 'desc')
->get()
->groupBy('application.name')
->sortKeys();
}
public function revokeToken($tokenId)
{
$token = AuthenticationToken::where('id', $tokenId)
->where('user_id', Auth::id())
->first();
if ($token) {
$token->delete();
$this->dispatch('token-revoked');
}
}
public function render()
{
return view('livewire.manage-authentication-tokens')->title('Authentication Tokens');
}
}