snipe-it/app/Http/Livewire/PersonalAccessTokens.php

41 lines
920 B
PHP
Raw Normal View History

2023-11-14 09:50:27 -08:00
<?php
namespace App\Http\Livewire;
use Illuminate\Support\Facades\Auth;
2023-11-15 14:27:01 -08:00
use Illuminate\Support\Facades\Log;
2023-11-14 09:50:27 -08:00
use Illuminate\View\View;
use Livewire\Component;
class PersonalAccessTokens extends Component
{
2023-11-15 14:51:09 -08:00
public $name;
2023-11-14 09:50:27 -08:00
public function render()
{
return view('livewire.personal-access-tokens', [
'tokens' => Auth::user()->tokens,
]);
}
public function rules(): array
{
return [
2023-11-15 14:55:21 -08:00
'name' => 'required|string|max:255',
2023-11-14 09:50:27 -08:00
'scopes' => 'nullable|array',
];
}
public function createToken(): void
{
2023-11-15 14:51:09 -08:00
Auth::user()->createToken($this->name);
2023-11-14 09:50:27 -08:00
}
public function deleteToken($tokenId): void
{
2023-11-15 14:27:01 -08:00
Log::info('poo');
//this needs safety (though the scope of auth::user might kind of do it...)
//seems like it does, test more
Auth::user()->tokens()->find($tokenId)->delete();
2023-11-14 09:50:27 -08:00
}
}