diff --git a/public_html/index.php b/public_html/index.php
index 0e7c4bb..51542f6 100644
--- a/public_html/index.php
+++ b/public_html/index.php
@@ -171,31 +171,9 @@ function filter_public_pages($pages) {
}
$public_pages = filter_public_pages($public_pages);
-// Check session and redirect if needed
-$currentUser = null;
-if ($validSession) {
- // Session is OK
- $currentUser = Session::getUsername();
-} else if (!in_array($page, $public_pages)) {
- // Session expired/invalid, page needs login
- if (isset($_SESSION['LAST_ACTIVITY']) && !isset($_SESSION['session_timeout_shown'])) {
- // Only show session timeout message if there was an active session
- // and we haven't shown it yet
- Feedback::flash('LOGIN', 'SESSION_TIMEOUT');
- $_SESSION['session_timeout_shown'] = true;
- // Cleanup session but keep flash messages
- $flash_messages = $_SESSION['flash_messages'] ?? [];
- Session::cleanup($config);
- $_SESSION['flash_messages'] = $flash_messages;
- }
- $loginUrl = $app_root . '?page=login';
- $trimmed = trim($page, '/?');
- if (!in_array($trimmed, INVALID_REDIRECT_PAGES, true)) {
- $loginUrl .= '&redirect=' . urlencode($_SERVER['REQUEST_URI']);
- }
- header('Location: ' . $loginUrl);
- exit();
-}
+// Dispatch routing and auth
+require_once __DIR__ . '/../app/core/Router.php';
+$currentUser = \App\Core\Router::checkAuth($config, $app_root, $public_pages, $page);
// connect to db of Jilo Web
require '../app/classes/database.php';