From 847b3627888060f9c538f178fbf1f95614c2f411 Mon Sep 17 00:00:00 2001 From: Chris Friemann Date: Wed, 24 Jan 2024 15:28:56 +0100 Subject: [PATCH] WIP feat: add auth --- src/app/Http/Kernel.php | 2 ++ .../Http/Middleware/HandleInertiaRequests.php | 26 +++++++++---------- src/resources/vue/pages/admin/index.vue | 16 +++++++----- src/resources/vue/pages/admin/items/index.vue | 7 +++-- src/routes/web.php | 4 +-- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/app/Http/Kernel.php b/src/app/Http/Kernel.php index fd469a6..36342e8 100644 --- a/src/app/Http/Kernel.php +++ b/src/app/Http/Kernel.php @@ -65,5 +65,7 @@ class Kernel extends HttpKernel 'signed' => \App\Http\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + 'terminal' => \App\Http\Middleware\TerminalMiddleWare::class, + 'admin' => \App\Http\Middleware\AdminMiddleWare::class, ]; } diff --git a/src/app/Http/Middleware/HandleInertiaRequests.php b/src/app/Http/Middleware/HandleInertiaRequests.php index 8c85cd2..0b0c9be 100644 --- a/src/app/Http/Middleware/HandleInertiaRequests.php +++ b/src/app/Http/Middleware/HandleInertiaRequests.php @@ -27,17 +27,17 @@ public function version(Request $request): ?string return parent::version($request); } - /** - * Defines the props that are shared by default. - * - * @see https://inertiajs.com/shared-data - * @param \Illuminate\Http\Request $request - * @return array - */ - public function share(Request $request): array - { - return array_merge(parent::share($request), [ - // - ]); - } + /** + * Defines the props that are shared by default. + * + * @see https://inertiajs.com/shared-data + * @param \Illuminate\Http\Request $request + * @return array + */ + public function share(Request $request): array + { + return array_merge(parent::share($request), [ + 'user' => fn() => auth()->user() + ]); + } } diff --git a/src/resources/vue/pages/admin/index.vue b/src/resources/vue/pages/admin/index.vue index eb282fb..f424239 100644 --- a/src/resources/vue/pages/admin/index.vue +++ b/src/resources/vue/pages/admin/index.vue @@ -40,19 +40,21 @@ diff --git a/src/routes/web.php b/src/routes/web.php index 1bce344..a8da7c7 100644 --- a/src/routes/web.php +++ b/src/routes/web.php @@ -20,8 +20,8 @@ Route::get('/', [IndexController::class, 'index']); -Route::get('/admin', [AdminController::class, 'index']); -Route::get('/admin/items', [AdminController::class, 'items']); +Route::get('/admin', [AdminController::class, 'index'])->middleware('admin'); +Route::get('/admin/items', [AdminController::class, 'items'])->middleware('admin'); Route::get('/terminal', [AppController::class, 'index']); Route::post('/auth', [SessionController::class, 'auth'])->name('auth');