41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Web\Profile;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Repositories\Session\SessionRepository;
|
|
use App\Support\SessionPayload;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response as InertiaResponse;
|
|
|
|
class SessionsController extends Controller
|
|
{
|
|
public function __construct(private readonly SessionRepository $sessions) {}
|
|
|
|
public function index(): InertiaResponse
|
|
{
|
|
$user = auth()->user();
|
|
|
|
return Inertia::render('users/Sessions', [
|
|
'adminView' => false,
|
|
'user' => [
|
|
'id' => $user->id,
|
|
'nameOrEmail' => $user->present()->nameOrEmail,
|
|
],
|
|
'sessions' => SessionPayload::collection(
|
|
$this->sessions->getUserSessions($user->id),
|
|
fn (string $sessionId) => route('profile.sessions.invalidate', $sessionId)
|
|
),
|
|
]);
|
|
}
|
|
|
|
public function destroy($session): RedirectResponse
|
|
{
|
|
$this->sessions->invalidateSession($session->id);
|
|
|
|
return redirect()->route('profile.sessions')
|
|
->withSuccess(__('Session invalidated successfully.'));
|
|
}
|
|
}
|