Skip to content

Commit 9539e21

Browse files
authored
Handle invalid svg icon in generic-oidc provider gracefully (#2216)
1 parent 33660f6 commit 9539e21

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

app/Filament/Admin/Pages/Settings.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use App\Traits\Filament\CanCustomizeHeaderWidgets;
1414
use App\Traits\Filament\CanCustomizeTabs;
1515
use BackedEnum;
16+
use BladeUI\Icons\Exceptions\SvgNotFound;
17+
use BladeUI\Icons\Factory as IconFactory;
1618
use Exception;
1719
use Filament\Actions\Action;
1820
use Filament\Actions\ActionGroup;
@@ -68,6 +70,8 @@ class Settings extends Page implements HasSchemas
6870

6971
protected CaptchaService $captchaService;
7072

73+
protected IconFactory $iconFactory;
74+
7175
/** @var array<mixed>|null */
7276
public ?array $data = [];
7377

@@ -76,11 +80,12 @@ public function mount(): void
7680
$this->form->fill();
7781
}
7882

79-
public function boot(OAuthService $oauthService, AvatarService $avatarService, CaptchaService $captchaService): void
83+
public function boot(OAuthService $oauthService, AvatarService $avatarService, CaptchaService $captchaService, IconFactory $iconFactory): void
8084
{
8185
$this->oauthService = $oauthService;
8286
$this->avatarService = $avatarService;
8387
$this->captchaService = $captchaService;
88+
$this->iconFactory = $iconFactory;
8489
}
8590

8691
public static function canAccess(): bool
@@ -565,9 +570,18 @@ private function oauthSettings(): array
565570
foreach ($oauthSchemas as $schema) {
566571
$key = $schema->getConfigKey();
567572

573+
$icon = $schema->getIcon();
574+
if (is_string($icon)) {
575+
try {
576+
$this->iconFactory->svg($icon);
577+
} catch (SvgNotFound) {
578+
$icon = null;
579+
}
580+
}
581+
568582
$formFields[] = Section::make($schema->getName())
569583
->columns(5)
570-
->icon($schema->getIcon() ?? TablerIcon::BrandOauth)
584+
->icon($icon ?? TablerIcon::BrandOauth)
571585
->collapsed(fn () => !$schema->isEnabled())
572586
->collapsible()
573587
->schema([

app/Filament/Pages/Auth/Login.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use App\Extensions\Captcha\CaptchaService;
66
use App\Extensions\OAuth\OAuthService;
7+
use BladeUI\Icons\Exceptions\SvgNotFound;
8+
use BladeUI\Icons\Factory as IconFactory;
79
use Filament\Actions\Action;
810
use Filament\Auth\Pages\Login as BaseLogin;
911
use Filament\Forms\Components\TextInput;
@@ -19,10 +21,13 @@ class Login extends BaseLogin
1921

2022
protected CaptchaService $captchaService;
2123

22-
public function boot(OAuthService $oauthService, CaptchaService $captchaService): void
24+
protected IconFactory $iconFactory;
25+
26+
public function boot(OAuthService $oauthService, CaptchaService $captchaService, IconFactory $iconFactory): void
2327
{
2428
$this->oauthService = $oauthService;
2529
$this->captchaService = $captchaService;
30+
$this->iconFactory = $iconFactory;
2631
}
2732

2833
public function form(Schema $schema): Schema
@@ -87,9 +92,18 @@ protected function getOAuthFormComponent(): Component
8792
$color = $schema->getHexColor();
8893
$color = is_string($color) ? Color::hex($color) : null;
8994

95+
$icon = $schema->getIcon();
96+
if (is_string($icon)) {
97+
try {
98+
$this->iconFactory->svg($icon);
99+
} catch (SvgNotFound) {
100+
$icon = null;
101+
}
102+
}
103+
90104
$actions[] = Action::make("oauth_$id")
91105
->label($schema->getName())
92-
->icon($schema->getIcon())
106+
->icon($icon)
93107
->color($color)
94108
->url(route('auth.oauth.redirect', ['driver' => $id], false));
95109
}

0 commit comments

Comments
 (0)