diff --git a/CLAUDE.md b/CLAUDE.md index 0b4a078..7af6d30 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -78,4 +78,7 @@ AuthentiKate is a lightweight SSO/OIDC solution built with Laravel and Livewire, - OAuth keys stored in `storage/oauth/` - Uses Laravel's built-in authentication system - Email verification and password reset supported -- Uses the free version of FluxUI. A livewire component library. \ No newline at end of file +- Uses the free version of FluxUI. A livewire component library. + +## Code Guidance +- Stop initializing collections using collect(). This is not compatible with Database\Eloquent\Collection. It is also not necessary to do this since the components are only visible to the admin \ No newline at end of file diff --git a/app/Livewire/ManageUsers.php b/app/Livewire/ManageUsers.php index d4b1746..26a529b 100644 --- a/app/Livewire/ManageUsers.php +++ b/app/Livewire/ManageUsers.php @@ -50,6 +50,25 @@ class ManageUsers extends Component $this->users = User::all(); } + public function changeUserRole(User $user, string $role) + { + $this->authorize('update', $user); + + // Prevent admins from demoting themselves + if ($user->id === auth()->id() && $role === 'user') { + session()->flash('error', 'You cannot demote yourself from admin.'); + return; + } + + $isAdmin = $role === 'admin'; + $user->update(['is_admin' => $isAdmin]); + + // Refresh the data + $this->users = User::all(); + + session()->flash('success', "User role updated to {$role}."); + } + public function render() { return view('livewire.manage-users'); diff --git a/resources/views/livewire/manage-users.blade.php b/resources/views/livewire/manage-users.blade.php index b579c76..e30e6b5 100644 --- a/resources/views/livewire/manage-users.blade.php +++ b/resources/views/livewire/manage-users.blade.php @@ -3,16 +3,42 @@