<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

namespace App\Listeners;

use App\Models\User;
use Illuminate\Auth\Events\Logout;

class RevokeApiToken
{
    public function handle(Logout $event): void
    {
        /** @var User $user */
        $user = $event->user;

        if ($tokenId = session('api_token_id')) {
            $user?->tokens()->where('id', $tokenId)->delete();
        }

        session()->forget(['api_token', 'api_token_id']);
    }
}
