diff --git a/app/Models/User.php b/app/Models/User.php index f6ba1d2..c483a00 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,6 +4,8 @@ // use Illuminate\Contracts\Auth\MustVerifyEmail; use Database\Factories\UserFactory; +use Filament\Models\Contracts\FilamentUser; +use Filament\Panel; use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Attributes\Hidden; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -12,11 +14,23 @@ #[Fillable(['name', 'email', 'password'])] #[Hidden(['password', 'remember_token'])] -class User extends Authenticatable +class User extends Authenticatable implements FilamentUser { /** @use HasFactory */ use HasFactory, Notifiable; + /** + * Determine whether the user may access the given Filament panel. + * + * Super Stack ships without public registration, so every user in the + * database is one you created on purpose. Tighten this before you open + * sign-ups: check a role, an `is_admin` column, or the email domain. + */ + public function canAccessPanel(Panel $panel): bool + { + return true; + } + /** * Get the attributes that should be cast. * diff --git a/tests/Feature/AdminPanelTest.php b/tests/Feature/AdminPanelTest.php index 4e212b0..7e02d0a 100644 --- a/tests/Feature/AdminPanelTest.php +++ b/tests/Feature/AdminPanelTest.php @@ -17,8 +17,16 @@ $response->assertOk(); }); -test('authenticated users can access admin dashboard in local environment', function () { - config(['app.env' => 'local']); +test('authenticated users can access the admin dashboard', function () { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->get('/admin'); + + $response->assertOk(); +}); + +test('admin access does not depend on the local environment', function () { + config(['app.env' => 'production']); $user = User::factory()->create();