Authentication: All users can access Filament
Hello, guys. I have two applications: client(the website) and api with Filament.
I am using Laravel Sanctum for register/login only to the website not in the admin panel but as I saw, all the users created from the website can also access the Filament Admin Panel. How can I allow only the filament user(or specific user ) to access the admin panel?
I say something like this, I put it in the User Model but it's not working
'public function isFilamentAdmin() { return $this->email === '[email protected]'; }'
'public function isFilamentAdmin() { return $this->email === '[email protected]'; }'
15 Replies
did you add
implements FilamentUser
?
and for code use proper syntax. read #✅┊rulesYes, I added FilamentUser
add
dd($this->email)
to check if it gets emailit doesn't display anything
Where do use
isFilamentAdmin()
?
And where did you add canAccessFilament()
?Did you read the docs on this?
https://filamentphp.com/docs/2.x/admin/users#authorizing-access-to-the-admin-panel
Yes, I read the documentation. I added canAccessFilament() and isFilamentAdmin() in UserModel
You only showed
isFilamentAdmin()
. Can you show the full model? Is the APP_ENV
set to something else than local
?APP_ENV is set to local.
That's the issue.
canAccessFilament()
only has an effect on non-local environments
Btw. code formatting required backticks. If you can't find them on your keyboard, you can copy them from #✅┊rules 😅Understood now
Should I do some changes in my model ? I pushed the changes to integration and has no effect. I can sign in with all the users. I hope I am clear because I don't know how to explain 😅
Which changes? Did you change the
APP_ENV
to something non-local?APP_ENV=staging
Okay, but you still haven't restricted them in any way, right?
Right
Done. I put a rule in canAccessFilament(). Thank you 😀