Initial commit: Pulse web app
This commit is contained in:
120
src/App.jsx
Normal file
120
src/App.jsx
Normal file
@@ -0,0 +1,120 @@
|
||||
import { useEffect } from "react"
|
||||
import { Routes, Route, Navigate } from "react-router-dom"
|
||||
import { useAuthStore } from "./store/auth"
|
||||
import Login from "./pages/Login"
|
||||
import Register from "./pages/Register"
|
||||
import Home from "./pages/Home"
|
||||
import Habits from "./pages/Habits"
|
||||
import Tasks from "./pages/Tasks"
|
||||
import VerifyEmail from "./pages/VerifyEmail"
|
||||
import ResetPassword from "./pages/ResetPassword"
|
||||
import ForgotPassword from "./pages/ForgotPassword"
|
||||
import Stats from "./pages/Stats"
|
||||
|
||||
function ProtectedRoute({ children }) {
|
||||
const { isAuthenticated, isLoading } = useAuthStore()
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-surface-50">
|
||||
<div className="w-10 h-10 border-4 border-primary-500 border-t-transparent rounded-full animate-spin" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/login" replace />
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
|
||||
function PublicRoute({ children }) {
|
||||
const { isAuthenticated, isLoading } = useAuthStore()
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-surface-50">
|
||||
<div className="w-10 h-10 border-4 border-primary-500 border-t-transparent rounded-full animate-spin" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isAuthenticated) {
|
||||
return <Navigate to="/" replace />
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const initialize = useAuthStore((s) => s.initialize)
|
||||
|
||||
useEffect(() => {
|
||||
initialize()
|
||||
}, [initialize])
|
||||
|
||||
return (
|
||||
<Routes>
|
||||
<Route
|
||||
path="/login"
|
||||
element={
|
||||
<PublicRoute>
|
||||
<Login />
|
||||
</PublicRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/register"
|
||||
element={
|
||||
<PublicRoute>
|
||||
<Register />
|
||||
</PublicRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/forgot-password"
|
||||
element={
|
||||
<PublicRoute>
|
||||
<ForgotPassword />
|
||||
</PublicRoute>
|
||||
}
|
||||
/>
|
||||
<Route path="/verify-email" element={<VerifyEmail />} />
|
||||
<Route path="/reset-password" element={<ResetPassword />} />
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Home />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/habits"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Habits />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/tasks"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Tasks />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/stats"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Stats />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user