feat(dev): seeders + DevQuickLogin with double-defense guard
parent
bc6fff37a7
commit
4854c6313d
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\User;
|
||||
use Livewire\Component;
|
||||
|
||||
class DevQuickLogin extends Component
|
||||
{
|
||||
public function loginAs(string $email): void
|
||||
{
|
||||
// Double defense
|
||||
abort_unless(app()->isLocal() && env('ALLOW_QUICK_LOGIN', false), 403);
|
||||
|
||||
$user = User::withoutGlobalScopes()->where('email', $email)->firstOrFail();
|
||||
auth()->login($user);
|
||||
$this->redirect('/dashboard');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$users = User::withoutGlobalScopes()->get(['id', 'name', 'email', 'uuid']);
|
||||
return view('livewire.dev-quick-login', compact('users'));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<div class="p-8 max-w-lg mx-auto">
|
||||
<h1 class="text-2xl font-bold mb-6 text-[--color-text-primary]">Quick Login (Dev Only)</h1>
|
||||
<div class="space-y-2">
|
||||
@foreach($users as $user)
|
||||
<button
|
||||
wire:click="loginAs('{{ $user->email }}')"
|
||||
class="w-full text-left px-4 py-3 rounded-lg border border-[--color-border-subtle] hover:bg-white transition-colors"
|
||||
>
|
||||
<span class="font-semibold">{{ $user->name }}</span>
|
||||
<span class="text-sm text-[--color-text-muted] ml-2">{{ $user->email }}</span>
|
||||
</button>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -16,3 +16,8 @@ Route::get('/lizenz-abgelaufen', fn() => view('lizenz-abgelaufen'))->name('lizen
|
|||
Route::view('profile', 'profile')->middleware(['auth'])->name('profile');
|
||||
|
||||
require __DIR__.'/auth.php';
|
||||
|
||||
// Quick-Login: double-defense (isLocal + ALLOW_QUICK_LOGIN env)
|
||||
if (app()->isLocal() && env('ALLOW_QUICK_LOGIN', false)) {
|
||||
Route::get('/dev/quick-login', \App\Livewire\DevQuickLogin::class)->name('dev.quick-login');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
use function Pest\Laravel\get;
|
||||
|
||||
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
it('Quick-Login-Route in local-Umgebung verfügbar', function () {
|
||||
// phpunit.xml.dist sets ALLOW_QUICK_LOGIN=true and APP_ENV=testing
|
||||
// But route is only registered when app()->isLocal() — in testing env it's NOT local
|
||||
// So the route should NOT be registered in test env
|
||||
get('/dev/quick-login')->assertNotFound();
|
||||
});
|
||||
Loading…
Reference in New Issue