diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php
new file mode 100644
index 0000000..c48b28b
--- /dev/null
+++ b/app/Http/Middleware/Authenticate.php
@@ -0,0 +1,19 @@
+cookieService = $cookieService;
+ $this->apiService = $apiService;
+ }
+
+ public function handle(Request $request, Closure $next)
+ {
+ $token = $this->cookieService->getCookie('TOKEN');
+ $publicRoutes = ['/', '/login', '/registration', '/change-password', '/topup-success-page', '/topup-error-page'];
+
+ if ($token) {
+ try {
+ $response = $this->apiService->post('adminProfile');
+ if ($response) {
+ Session::put('userInfo', $response);
+ Session::put('isAuthenticated', true);
+
+ if (in_array($request->path(), $publicRoutes)) {
+ return redirect('/user-management');
+ }
+ }
+ } catch (\Exception $e) {
+ Log::error('Failed to load user data', ['error' => $e->getMessage(), 'source' => 'CheckAuth']);
+ Session::flash('error', 'Something went wrong loading user data.');
+ }
+ }
+
+ return $next($request);
+ }
+}
\ No newline at end of file
diff --git a/bootstrap/app.php b/bootstrap/app.php
index 1edf064..e1241c7 100644
--- a/bootstrap/app.php
+++ b/bootstrap/app.php
@@ -3,6 +3,7 @@
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
+use App\Http\Middleware\CheckAuth;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
@@ -12,7 +13,12 @@ return Application::configure(basePath: dirname(__DIR__))
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
- //
+ $middleware->web(append: [
+ CheckAuth::class,
+ ]);
+ $middleware->alias([
+ 'auth' => \App\Http\Middleware\Authenticate::class,
+ ]);
})
->withExceptions(function (Exceptions $exceptions) {
//
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php
index 95d51f4..e8e2ec0 100644
--- a/resources/views/layouts/app.blade.php
+++ b/resources/views/layouts/app.blade.php
@@ -1,24 +1,16 @@
-
+
-
-
- @yield('title')
-
-
- @livewireStyles
+
+
+ Laravel
+
-
- @livewire('header-dropdown', ['userInfo' => ['firstname' => 'John', 'lastname' => 'Doe']])
-
-
+
@yield('content')
-
-
- @livewireScripts
+
+ @stack('scripts')
\ No newline at end of file
diff --git a/routes/web.php b/routes/web.php
index 29a9922..3336ee9 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -133,3 +133,74 @@ Route::get('/multi-select-options', function () { return view('multi-select-opti
Route::get('/', function () {
return view('welcome');
});
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// group(function () {
+// // Public Routes
+// Route::get('/', fn () => redirect('/login'));
+// Route::get('/login', Login::class)->name('login');
+// Route::get('/registration', Registration::class)->name('registration');
+// Route::get('/change-password', ChangePassword::class)->name('change-password');
+// Route::get('/topup-success-page', PublicTopSuccessPage::class)->name('topup-success');
+// Route::get('/topup-error-page', PublicTopErrorPage::class)->name('topup-error');
+
+// // Private Routes (require authentication)
+// Route::middleware(['auth'])->group(function () {
+// Route::get('/user-management', UserManagement::class)->name('user-management');
+// Route::get('/notifications', Notifications::class)->name('notifications');
+// Route::get('/member-management', MemberManagement::class)->name('member-management');
+// Route::get('/home-page', PhotoSlider::class)->name('home-page');
+// Route::get('/promotions', Promotions::class)->name('promotions');
+// Route::get('/top-up', TopUp::class)->name('top-up');
+// Route::get('/about-us', CardTypes::class)->name('about-us');
+// Route::get('/reports', Reports::class)->name('reports');
+// Route::get('/stations', StationLocator::class)->name('stations');
+// Route::get('/branches', Branches::class)->name('branches');
+// Route::get('/fuels', Fuels::class)->name('fuels');
+// Route::get('/system-parameters', SystemPreferences::class)->name('system-parameters');
+// Route::get('/my-profile', MyProfile::class)->name('my-profile');
+// });
+
+// // 404 Route
+// Route::get('/404', Page404::class)->name('404');
+// Route::any('{any}', fn () => redirect()->route('404'))->where('any', '.*');
+// });