Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add the ability to define a post logout route #300

Merged
merged 2 commits into from Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config/filament.php
Expand Up @@ -49,6 +49,7 @@

'auth' => [
'guard' => env('FILAMENT_AUTH_GUARD', 'filament'),
'logout_redirect_route' => 'filament.auth.login',
],

/*
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Livewire/Auth/Logout.php
Expand Up @@ -18,6 +18,8 @@ public function submit()
{
Filament::auth()->logout();

return redirect()->route('filament.auth.login');
return redirect()->route(
config('filament.auth.logout_redirect_route', 'filament.auth.login'),
);
}
}
21 changes: 21 additions & 0 deletions tests/Feature/Auth/LogoutTest.php
Expand Up @@ -5,6 +5,7 @@
use Filament\Http\Livewire\Auth\Logout;
use Filament\Models\User;
use Filament\Tests\TestCase;
use Illuminate\Support\Facades\Route;
use Livewire\Livewire;

class LogoutTest extends TestCase
Expand All @@ -22,4 +23,24 @@ public function can_log_out()

$this->assertGuest();
}

/** @test */
public function can_redirect_to_custom_route_after_log_out()
{
Route::get('custom-logout-redirect', function () {
return true;
})->name('filament.testing.auth.custom-logout-redirect');

$this->app['config']->set('filament.auth.logout_redirect_route', 'filament.testing.auth.custom-logout-redirect');

$user = User::factory()->create();

$this->be($user);

Livewire::test(Logout::class)
->call('submit')
->assertRedirect(route('filament.testing.auth.custom-logout-redirect'));

$this->assertGuest();
}
}