Skip to content

feat: add configurable authentication guard#34

Closed
muyaedward wants to merge 1 commit intoawcodes:3.xfrom
muyaedward:feat/add-configurable-auth-guard
Closed

feat: add configurable authentication guard#34
muyaedward wants to merge 1 commit intoawcodes:3.xfrom
muyaedward:feat/add-configurable-auth-guard

Conversation

@muyaedward
Copy link

Description

Adds the ability to configure a custom authentication guard for Mason routes, eliminating the need to override routes in AppServiceProvider when using multiple authentication guards.

Problem

Currently, Mason's routes are hardcoded with the default auth middleware, which uses the default authentication guard from config/auth.php. This causes issues when:

  • Using Filament admin panels with custom guards (e.g., admin)
  • Running multiple authentication systems (customer vs admin)
  • Using API guards like sanctum or custom guards

Current workaround:

// AppServiceProvider.php - Required workaround
protected function registerMasonRoutes(): void
{
    Route::post('/mason/preview', function (Request $request) {
        return app(\Awcodes\Mason\Http\Controllers\MasonController::class)->preview($request);
    })->middleware(['web', 'auth:admin']); // Must override to use custom guard
}

Solution

Add a simple guard configuration option to config/mason.php:

return [
    // ... existing config ...
    
    'guard' => null, // null = default guard, 'admin' = admin guard, etc.
];

Changes

1. config/mason.php - New configuration option

  • Added guard config option with comprehensive documentation
  • Defaults to null (uses default auth guard)
  • Supports any Laravel authentication guard

2. routes/web.php - Dynamic guard usage

  • Routes now read guard from config
  • Maintains backward compatibility
  • Clean implementation using route groups

Usage

For Filament Admin Panels:

// config/mason.php
'guard' => 'admin',

For API applications:

// config/mason.php
'guard' => 'sanctum',

For default behavior (no change needed):

// config/mason.php
'guard' => null, // Or omit entirely

Benefits

Simple - One-line configuration
Backward Compatible - Existing installations work unchanged
Flexible - Works with any Laravel guard
Clean - Removes need for route overrides
Well Documented - Clear config comments

Testing

  • ✅ Tested with guard => null (default behavior maintained)
  • ✅ Tested with guard => 'admin' (Filament admin panel integration)
  • ✅ Verified backward compatibility
  • ✅ Confirmed route middleware application

Related Issues

This addresses a common pain point for users integrating Mason with Filament admin panels and other multi-guard Laravel applications.

Migration Guide

No migration needed! Existing installations continue working without changes. To use a custom guard:

  1. Publish config: php artisan vendor:publish --tag=mason-config
  2. Set guard: 'guard' => 'admin' in config/mason.php
  3. Remove route overrides from AppServiceProvider (if any)

Adds ability to specify a custom authentication guard in mason.php config.
This allows Mason to work seamlessly with applications that use multiple
guards, such as Filament admin panels with custom 'admin' guards.

Configuration:
- New 'guard' option in config/mason.php
- Defaults to null (uses default auth guard)
- Set to 'admin', 'web', 'sanctum', etc. as needed

Benefits:
- Eliminates need to override Mason routes in AppServiceProvider
- Maintains backward compatibility (null = default guard)
- Simple one-line configuration
- Works with any Laravel authentication guard

Example usage:
```php
// config/mason.php
'guard' => 'admin', // For Filament admin panels
```

Closes requirement for custom guard support in multi-guard applications.
@awcodes
Copy link
Owner

awcodes commented Feb 5, 2026

Thank you for the PR, but I want to go with a more open ended solution. It will be available in the next release later today.

@awcodes awcodes closed this Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants