Enable/Disable Login method

Hi, Does anybody have an idea about enabling or disabling login during the boot process? I think it's a bit tricky.
11 Replies
North
North6mo ago
What boot process?
misaf
misafOP6mo ago
Service provider I want to get data from the database and then enable or disable the login or register method.
North
North6mo ago
There's no known way to disable login, you can use the Filaments components to create a custom Livewire component and display it If you want to use Filament components to create a custom page which shows data, just use Livewire with it
North
North6mo ago
Tuto1902
YouTube
Filament Tables with Livewire: Full Page Component! ✨
The great thing about Filament is that you don't have to use the Panel Builder. You can create a complete C.R.U.D. application using just one full-page Livewire component and the Filament Tables package. This video will show you how to do that, using a small example project. https://github.com/tuto1902/livewire-medication-reminder 00:00 Intro ...
North
North6mo ago
It's an old Arturo's vídeo, but still working fine, if you just want to display data using Filament
misaf
misafOP6mo ago
Some methods, like login/register or domains, cannot be used in the boot method; therefore, we can't make them dynamic
North
North6mo ago
Can you provide more detail?
tuto1902
tuto19026mo ago
Well, what I would do is conditionally call the ->login() method in the AdminPanelServiceProvider. I don't know what kind of database data you need but you should have access to models and query builders at that point
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
$loginEnabled = true;

$panel = $panel
->default()
->id('admin')
// all the config options except login...
->path('admin');

// do stuff here

if ($loginEnabled) {
$panel = $panel->login();
}

return $panel;
}
}
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
$loginEnabled = true;

$panel = $panel
->default()
->id('admin')
// all the config options except login...
->path('admin');

// do stuff here

if ($loginEnabled) {
$panel = $panel->login();
}

return $panel;
}
}
North
North6mo ago
I guess if you remove login(), it complains about route for login doesn't exist
North
North6mo ago
Yep, tested here with filament panels (at least)
No description
tuto1902
tuto19026mo ago
Oh, here's the official docs for guest access. So all you need to do now is prepare the widgets and authMiddleware arrays so you can append Authenticate::class and AccountWidget::class depending on the database data you are using https://filamentphp.com/docs/3.x/panels/users#setting-up-guest-access-to-a-panel
$widgetsArray = [];
$authMiddlewareArray = [];
// Do stuff with arrays
$panel
...
->widgets([
Widgets\FilamentInfoWidget::class,
...$widgetsArray
])
->authMiddleware([
...$authMiddlewareArray
]);
$widgetsArray = [];
$authMiddlewareArray = [];
// Do stuff with arrays
$panel
...
->widgets([
Widgets\FilamentInfoWidget::class,
...$widgetsArray
])
->authMiddleware([
...$authMiddlewareArray
]);
Want results from more Discord servers?
Add your server