When you are using Filament Admin, you might encounter that when you publish your site to production, it doesn't work. The login shows up, but after logging in, you most probably end up with a plain 404 error. Doing the same locally works just fine.

By default, all App\Models\Users can access Filament locally. To allow them to access Filament in production, you must take a few extra steps to ensure that only the correct users have access to the admin panel.

To set up your App\Models\User to access Filament in non-local environments, you must implement the FilamentUser contract:

namespace App\Models;

use Filament\Models\Contracts\FilamentUser;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements FilamentUser
{
    // ...

    public function canAccessFilament(): bool
    {
        return str_ends_with($this->email, '@yourdomain.com')
            && $this->hasVerifiedEmail();
    }
}

The canAccessFilament() method returns true or false depending on whether the user is allowed to access Filament. In this example, we check if the user's email ends with @yourdomain.com and if they have verified their email address.

This is hidden somewhere in the Filament Documentation ;-).