Routing Modules Through Filament: Fixing Login Redirects
The Reimpact platform is undergoing a transition of its module URLs from Nova to Filament. This post details how we fixed a login redirect issue that arose during this migration.
The Problem
After migrating the Packaging module to Filament, users were experiencing redirect issues upon login when the MODULE_SELECTOR_SYSTEM feature flag was enabled. The system was incorrectly routing users through Nova, even though the module was now managed by Filament.
The Cause
The ModuleUrlService was generating module URLs using Nova::path(). This needed to be updated to use the Filament panel path for migrated modules. The core issue was the service's lack of awareness regarding which modules had been migrated to Filament.
The Solution
To address this, we introduced a FILAMENT_URLS override map. This map allows us to explicitly define which modules should resolve to their Filament panel path. This ensures that the ModuleUrlService correctly generates URLs for both Nova and Filament modules.
Here's a simplified example of how the URL service might be implemented:
class ModuleUrlService
{
private array $filamentUrls = [
'packaging' => '/admin/packaging',
];
public function getModuleUrl(string $moduleName): string
{
if (isset($this->filamentUrls[$moduleName])) {
return $this->filamentUrls[$moduleName];
}
return '/nova/' . $moduleName; // Default to Nova path
}
}
This approach allows for a gradual migration of modules to Filament without breaking existing functionality or requiring a complete rewrite of the URL generation logic.
The Takeaway
When migrating applications between different frameworks or systems, carefully manage URL generation to ensure proper routing and avoid redirect issues. Using an override map or similar mechanism provides a flexible way to handle the transition period.