filament-companies: Cannot assign null to property Wallo\FilamentCompanies\Http\Controllers\OAuthController::$registrationUrl of type string

when using an php artisan console command i’m now gettting this error after upgrading to version v3.2.2

Cannot assign null to property Wallo\FilamentCompanies\Http\Controllers\OAuthController::$registrationUrl of type string

  at vendor/andrewdwallo/filament-companies/src/Http/Controllers/OAuthController.php:58
     54▕         $this->updatesConnectedAccounts = $updatesConnectedAccounts;
     55▕         $this->invalidStateHandler = $invalidStateHandler;
     56▕ 
     57▕         $this->guard = Filament::auth();
  ➜  58▕         $this->registrationUrl = Filament::getRegistrationUrl();
     59▕         $this->loginUrl = Filament::getLoginUrl();
     60▕         $this->userPanel = FilamentCompanies::getUserPanel();
     61▕     }
     62▕ 

When i dd(Filament::getCurrentPanel()); just above $this->guard = Filament::auth(); it returns a panel which does not have filamentCompanies plugin registered / enabled.

changing this line resolves the issue:

$this->registrationUrl = Filament::getRegistrationUrl() ?? '';

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Comments: 25 (10 by maintainers)

Most upvoted comments

@VincentLahaye If you want only the “Main” panel to have a login/register, then it would be a better practice to do something along the lines of this.

In your “Main” panel, mark it as default like so:

class FilamentCompaniesServiceProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->default() // HERE
            ->id('company')
            ->path('company')
            ->login(Login::class)
            ->registration(Register::class)
            ...
    }
}

For your other panels, create a new class at app/Http/Middleware/Authenticate.php or use the default one provided by the Laravel skeleton, and use this code in it:

namespace App\Http\Middleware;

use Filament\Facades\Filament;
use Filament\Http\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
{
    /**
     * Redirect users who try to access other panel routes before being authenticated.
     */
    protected function redirectTo($request): ?string
    {
        return Filament::getDefaultPanel()->getLoginUrl();
    }
}

Then in the other panels (the non-main ones), replace the default Filament\Http\Middleware\Authenticate middleware provided by Filament with the new middleware from above like so:

namespace App\Providers\Filament;

use App\Http\Middleware\Authenticate;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->authMiddleware([
                Authenticate::class,
            ]);
    }
}

You can look at my ERPSAAS repository as an example.