From 7e7f322e21f89d770d5db1a9402d4655fe4cea79 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 8 Feb 2024 14:01:16 +0100 Subject: [PATCH] Refactor admin authentication and routing*** ***Add redirect for non-cloud users and instance admins without admin token.*** ***Always include admin route, regardless of cloud status. --- app/Livewire/Admin/Index.php | 5 ++++- routes/web.php | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Livewire/Admin/Index.php b/app/Livewire/Admin/Index.php index 75b3f1d22..95a7dd2ae 100644 --- a/app/Livewire/Admin/Index.php +++ b/app/Livewire/Admin/Index.php @@ -11,7 +11,10 @@ class Index extends Component public $users = []; public function mount() { - if (auth()->user()->id !== 0) { + if (!isCloud()) { + return redirect()->route('dashboard'); + } + if (!isInstanceAdmin() && session('adminToken') === null) { return redirect()->route('dashboard'); } $this->users = User::whereHas('teams', function ($query) { diff --git a/routes/web.php b/routes/web.php index bb3ca6e34..12e3c4a8d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -79,9 +79,7 @@ use App\Livewire\Waitlist\Index as WaitlistIndex; if (isDev()) { Route::get('/dev/compose', Compose::class)->name('dev.compose'); } -if (isCloud()) { - Route::get('/admin', AdminIndex::class)->name('admin.index'); -} +Route::get('/admin', AdminIndex::class)->name('admin.index'); Route::post('/forgot-password', [Controller::class, 'forgot_password'])->name('password.forgot'); Route::get('/api/v1/test/realtime', [Controller::class, 'realtime_test'])->middleware('auth');