mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-09 08:26:16 +00:00
refactor(frontend): optimise auth process
- Stops frontend trying to make calls that require auth before auth has occured - Stops frontend making calls that aren't necessary before auth has occured - Implements state machine to better handle auth phases
This commit is contained in:
@@ -2,6 +2,7 @@ import { Route, Routes } from "react-router-dom";
|
||||
import FirstTimeAdminSetup from "./components/FirstTimeAdminSetup";
|
||||
import Layout from "./components/Layout";
|
||||
import ProtectedRoute from "./components/ProtectedRoute";
|
||||
import { isAuthPhase } from "./constants/authPhases";
|
||||
import { AuthProvider, useAuth } from "./contexts/AuthContext";
|
||||
import { ThemeProvider } from "./contexts/ThemeContext";
|
||||
import { UpdateNotificationProvider } from "./contexts/UpdateNotificationContext";
|
||||
@@ -20,11 +21,14 @@ import Settings from "./pages/Settings";
|
||||
import Users from "./pages/Users";
|
||||
|
||||
function AppRoutes() {
|
||||
const { needsFirstTimeSetup, checkingSetup, isAuthenticated } = useAuth();
|
||||
const { needsFirstTimeSetup, authPhase, isAuthenticated } = useAuth();
|
||||
const isAuth = isAuthenticated(); // Call the function to get boolean value
|
||||
|
||||
// Show loading while checking if setup is needed
|
||||
if (checkingSetup) {
|
||||
// Show loading while checking setup or initialising
|
||||
if (
|
||||
isAuthPhase.initialising(authPhase) ||
|
||||
isAuthPhase.checkingSetup(authPhase)
|
||||
) {
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-primary-50 to-secondary-50 dark:from-secondary-900 dark:to-secondary-800 flex items-center justify-center">
|
||||
<div className="text-center">
|
||||
|
||||
Reference in New Issue
Block a user