Am I using the correct Middleware to Authenticate?

In my config: use App\Http\Middleware\Authenticate; // have also tried with same result // use Filament\Http\Middleware\Authenticate; 'middleware' => [ 'auth' => [ Authenticate::class, ], ... ``` My issue is that even with a user Model with ``` public function canAccessFilament(): bool { return false; } ``` Still all users can access admin pages Also .env has APP_ENV=staging I have seen answers using isFilamentAdmin()` but that is v1, right?
8 Replies
ddoddsr
ddoddsrOP2y ago
Sorry, cannot fix the backtics
Dennis Koch
Dennis Koch2y ago
You need triple backticks 😅 Did you clear your config?
ddoddsr
ddoddsrOP2y ago
yup, art config:clear INFO Configuration cache cleared successfully.
awcodes
awcodes2y ago
I think the can access filament only matters if the env is production. I could be wrong though.
ddoddsr
ddoddsrOP2y ago
changes the Authenticate to: use Filament\Http\Middleware\Authenticate; and now I get 403 on both as expected. now returning return $this->is_admin from canAccessFilament method allows the correct one thru, 403sthe correct one. I think I needed the config:clear Also .env has APP_ENV=staging
awcodes
awcodes2y ago
Hmm. Yea. Looking at the code, staging should be honored the same as production for the middleware.
ddoddsr
ddoddsrOP2y ago
I think changing back to use Filament\Http\Middleware\Authenticate; did it with a config:clear
Aubrey Robertson
Was having the same issue and that fixed it! Thank you.

Did you find this page helpful?