<?php

namespace App\Components;

use Livewire\Component;

class ExitImpersonation extends Component {
    public function render() {
        return view('components.exit-impersonation');
    }

    public function exit(): void {
        if (!session()->has('impersonator_id')) {
            return;
        }


        $impersonatorId = session()->pull('impersonator_id');
        session()->forget('impersonated_id');


        auth()->loginUsingId($impersonatorId);


        $this->redirectRoute('admin.users.index');
    }
}
