The panel worked locally and every login is a 403 in production
Without a FilamentUser contract, Filament decides who may enter the panel by reading one config value. It is the right default for a fresh install and the wrong one for every environment you deploy to.
ON THIS PAGE
The deploy went fine, and nobody can get in
You built the admin panel over a week of evenings. Resources, filters, a dashboard widget the operations team asked for. On your machine you log in, click around, everything works. You deploy on Friday afternoon, send the link, and the first reply is a screenshot of a bare 403 | Forbidden page.
The credentials are right. The login form did not complain. The user row is there, the password hash checks out, and the session cookie is set. The request simply gets as far as /admin and stops.
Nothing is broken. Filament is enforcing a rule you never wrote down, because you never had to: on your laptop, APP_ENV is local.
The rule lives in one line of middleware
Every panel route sits behind Filament\Http\Middleware\Authenticate. After it confirms that somebody is logged in, it asks a second question: may this user enter this panel? Here is the decision, straight from the Filament 5 source:
abort_if(
$user instanceof FilamentUser ?
(! $user->canAccessPanel($panel)) :
(config('app.env') !== 'local'),
403,
);
If your User model implements Filament\Models\Contracts\FilamentUser, Filament calls your canAccessPanel() method and believes the answer. If it does not, there is nobody to ask, so Filament falls back to the environment: anything other than exactly local is a 403.
That fallback is deliberate. A fresh install should be usable straight away on a developer machine, and an install that was pushed to a server by accident should not hand the panel to every account in the users table — including the customers who signed up through your public registration form. The Filament docs state it plainly: by default, all users can access Filament locally, and production needs extra steps.
It is not only production
The check is !== 'local', not === 'production'. Run the same authenticated request under each environment name and you get this:
APP_ENV=local GET /admin => 200
APP_ENV=testing GET /admin => 403
APP_ENV=staging GET /admin => 403
APP_ENV=production GET /admin => 403
So the first environment to break is usually not production at all. It is your staging box, or your test suite. Laravel's phpunit.xml sets APP_ENV to testing, which means a feature test that does actingAs($user)->get('/admin') fails with a 403 before you have written a single line of authorisation. If you have ever "fixed" that by forcing the environment back to local inside a test, you have hidden exactly the bug this article is about.
Why the login page does not warn you
The confusing part is that the login itself succeeds. Filament's login page does check panel access before it signs anyone in — but it only consults the contract:
protected function isUserAllowedToAccessPanel(Authenticatable $user): bool
{
if (! ($user instanceof FilamentUser)) {
return true;
}
return $user->canAccessPanel(Filament::getCurrentOrDefaultPanel());
}
Without the contract, that method returns true, the user is logged in, and they are redirected straight into the middleware that refuses them. A real login against a production-configured app shows both halves:
login form: no errors, redirect to /admin
login ok, then GET /admin => 403
Once you do implement the contract, the behaviour changes shape. A user your method rejects never gets a session at all; the login form shows Filament's generic failure message, "These credentials do not match our records." That is the right outcome — it does not tell an attacker which emails belong to staff — but it means the two states look completely different to whoever is filing the bug report. A 403 after login means no contract. A credentials error for a correct password means your contract said no.
The fix: say who belongs, in code
Implement the contract on your user model and write a rule you would defend in a security review:
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements FilamentUser
{
public function canAccessPanel(Panel $panel): bool
{
return str_ends_with($this->email, '@yourcompany.com')
&& $this->hasVerifiedEmail();
}
}
That is the shape of the example in the Filament docs, and the verified-email check matters: without it, anyone who can register anything@yourcompany.com on a public form is in. A role or a boolean column is usually sturdier than an email domain:
public function canAccessPanel(Panel $panel): bool
{
return match ($panel->getId()) {
'admin' => $this->is_admin === true,
default => false,
};
}
You receive the $panel being entered, so one method covers every panel in the app. End the match with false, not true: a panel you add next quarter should start closed until someone decides who gets in.
The strict === true is not decoration. A user you have just created with create() does not carry the column's database default back onto the model, so is_admin is null until the row is reloaded — even with a boolean cast. Return that bare and the bool return type throws a TypeError, and your customer gets a 500 instead of a 403. That is exactly what the first run of the test below produced.
Resist the tempting one-liner return true;. It makes the 403 go away and opens the panel to every row in users. If your app has public sign-up, that is every member of the public.
Pin it with a test that runs outside local
Because the test environment is not local, a two-line test now covers the contract properly — no environment juggling required:
it('lets staff into the admin panel', function () {
$staff = User::factory()->create(['is_admin' => true]);
$this->actingAs($staff)->get('/admin')->assertOk();
});
it('keeps customers out of the admin panel', function () {
$customer = User::factory()->create(['is_admin' => false]);
$this->actingAs($customer)->get('/admin')->assertForbidden();
});
Run against the fixed model in a scratch application, the pair behaved exactly as intended:
staff => 200
customer => 403
The second test is the one that earns its keep. It fails the day somebody "temporarily" returns true from canAccessPanel() to unblock a demo.
What to change
Open your User model. If it does not implement FilamentUser, your panel works only where APP_ENV is exactly local, and you have either not deployed yet or you have a staging environment nobody can log in to.
Add the contract, write a canAccessPanel() that names a real condition — a role, a flag, a verified company address — and make the default for unknown panels false. Then add the two tests above, so the rule is checked in the testing environment on every run instead of being discovered by a colleague on Friday afternoon.
Finally, search your test suite and service providers for anything that forces app.env to local. Every one of those is a place where this check has been switched off rather than satisfied.