Skip to content

Commit

Permalink
Logout
Browse files Browse the repository at this point in the history
  • Loading branch information
ucan-lab committed Jun 30, 2023
1 parent 8cb316b commit 06cce5a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/app/Http/Controllers/LogoutController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Aws\CognitoIdentityProvider\AdminUserGlobalSignOut\AdminUserGlobalSignOut;
use App\Aws\CognitoIdentityProvider\AdminUserGlobalSignOut\AdminUserGlobalSignOutPayload;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

final readonly class LogoutController
{
public function __construct(private AdminUserGlobalSignOut $adminUserGlobalSignOut)
{
}

public function __invoke(): RedirectResponse
{
if (Auth::check()) {
/** @var User $user */
$user = Auth::user();

$payload = AdminUserGlobalSignOutPayload::create($user->username);
$this->adminUserGlobalSignOut->execute($payload);

Auth::logout();
Session::invalidate();
Session::regenerateToken();
}

return redirect()->route('welcome');
}
}
2 changes: 2 additions & 0 deletions src/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use App\Http\Controllers\LoginController;
use App\Http\Controllers\LogoutController;
use App\Http\Controllers\RegisterController;
use Illuminate\Support\Facades\Route;

Expand All @@ -27,4 +28,5 @@

Route::group(['middleware' => 'auth'], static function () {
Route::view('/dashboard', 'dashboard')->name('dashboard');
Route::post('/logout', LogoutController::class)->name('logout');
});

0 comments on commit 06cce5a

Please sign in to comment.