Move tokens to their own page
Some checks failed
linter / quality (push) Successful in 5m47s
tests / ci (push) Failing after 10m17s

This commit is contained in:
Javier Feliz 2025-08-02 15:54:30 -04:00
parent a6d3b533ca
commit 2e95a2a271
7 changed files with 88 additions and 7 deletions

View File

@ -5,8 +5,10 @@ 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]
@ -37,6 +39,6 @@ class ManageAuthenticationTokens extends Component
public function render()
{
return view('livewire.manage-authentication-tokens');
return view('livewire.manage-authentication-tokens')->title('Authentication Tokens');
}
}

View File

@ -19,6 +19,10 @@
wire:navigate>
{{ __('Apps') }}
</flux:navbar.item>
<flux:navbar.item icon="key" :href="route('tokens')" :current="request()->routeIs('tokens')"
wire:navigate>
{{ __('Tokens') }}
</flux:navbar.item>
@can('viewAny', App\Models\User::class)
<flux:navbar.item icon="users" :href="route('admin.users')" :current="request()->routeIs('admin.users')"
wire:navigate>
@ -96,6 +100,10 @@
:current="request()->routeIs('dashboard')" wire:navigate>
{{ __('Dashboard') }}
</flux:navlist.item>
<flux:navlist.item icon="key" :href="route('tokens')"
:current="request()->routeIs('tokens')" wire:navigate>
{{ __('Tokens') }}
</flux:navlist.item>
@can('viewAny', App\Models\User::class)
<flux:navlist.item icon="users" :href="route('admin.users')"
:current="request()->routeIs('admin.users')" wire:navigate>

View File

@ -14,6 +14,7 @@
<flux:navlist variant="outline">
<flux:navlist.group :heading="__('Platform')" class="grid">
<flux:navlist.item icon="home" :href="route('dashboard')" :current="request()->routeIs('dashboard')" wire:navigate>{{ __('Dashboard') }}</flux:navlist.item>
<flux:navlist.item icon="key" :href="route('tokens')" :current="request()->routeIs('tokens')" wire:navigate>{{ __('Tokens') }}</flux:navlist.item>
@can('viewAny', App\Models\User::class)
<flux:navlist.item icon="users" :href="route('admin.users')" :current="request()->routeIs('admin.users')" wire:navigate>{{ __('User Management') }}</flux:navlist.item>
@endcan

View File

@ -4,10 +4,6 @@
<livewire:forms.user-profile />
</div>
<div class="mt-4">
<livewire:manage-authentication-tokens />
</div>
@can('viewAny', App\Models\Application::class)
<div class="mt-4">
<livewire:app-container />
@ -20,7 +16,7 @@
<div class="p-6 text-gray-900">
<h3 class="text-lg font-medium">Welcome to AuthentiKate</h3>
<p class="mt-2 text-sm text-gray-600">
You can manage your profile and view your authentication tokens above.
You can manage your profile above and view your authentication tokens in the Tokens section.
</p>
</div>
</div>

View File

@ -1,4 +1,4 @@
<div>
<div class="max-w-4xl mx-auto py-12">
<x-card class="space-y-6 p-6">
<flux:heading size="lg">Authentication Tokens</flux:heading>
<flux:subheading>

View File

@ -2,6 +2,7 @@
use App\Http\Controllers\OIDCController;
use App\Livewire\ConsentScreen;
use App\Livewire\ManageAuthenticationTokens;
use App\Livewire\ManageUsers;
use App\Livewire\Settings\Appearance;
use App\Livewire\Settings\Password;
@ -24,6 +25,10 @@ Route::get('admin/users', ManageUsers::class)
->middleware(['auth', 'can:viewAny,App\Models\User'])
->name('admin.users');
Route::get('tokens', ManageAuthenticationTokens::class)
->middleware(['auth'])
->name('tokens');
Route::middleware(['auth'])->group(function () {
Route::redirect('settings', 'settings/profile');

View File

@ -0,0 +1,69 @@
<?php
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->admin = User::factory()->create(['is_admin' => true]);
$this->user = User::factory()->create(['is_admin' => false]);
});
describe('Tokens Page', function () {
it('allows any authenticated user to access the tokens page', function () {
$this->actingAs($this->user);
$response = $this->get(route('tokens'));
$response->assertStatus(200);
$response->assertSee('Authentication Tokens');
$response->assertSee('Manage your active authentication tokens');
});
it('allows admin users to access the tokens page', function () {
$this->actingAs($this->admin);
$response = $this->get(route('tokens'));
$response->assertStatus(200);
$response->assertSee('Authentication Tokens');
$response->assertSee('Manage your active authentication tokens');
});
it('redirects unauthenticated users to login', function () {
$response = $this->get(route('tokens'));
$response->assertRedirect(route('login'));
});
it('shows the tokens navigation link to all authenticated users', function () {
// Test regular user sees the link
$this->actingAs($this->user);
$response = $this->get(route('dashboard'));
$response->assertSee('Tokens');
// Test admin user also sees the link
$this->actingAs($this->admin);
$response = $this->get(route('dashboard'));
$response->assertSee('Tokens');
});
it('properly displays the page title', function () {
$this->actingAs($this->user);
$response = $this->get(route('tokens'));
$response->assertSee('<title>Authentication Tokens</title>', false);
});
it('shows empty state when user has no tokens', function () {
$this->actingAs($this->user);
$response = $this->get(route('tokens'));
$response->assertSee('No tokens');
$response->assertSee('authorized any applications');
});
});