System15 / frontend /src /components /ProtectedRoute.jsx
yamilogic's picture
Deploy SMTP Auth System to Hugging Face Space
50535d1
Raw
History Blame Contribute Delete
1.05 kB
import { Navigate } from "react-router-dom"
import { useAuth } from "../context/AuthContext"
export default function ProtectedRoute({ children }) {
const { user, loading } = useAuth()
if (loading) {
return (
<div style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
height: "80vh",
gap: "1rem"
}}>
<div style={{
width: "40px",
height: "40px",
border: "4px solid rgba(255, 255, 255, 0.1)",
borderTop: "4px solid var(--accent-color)",
borderRadius: "50%",
animation: "spin 1s linear infinite"
}} />
<p style={{ color: "var(--text-secondary)", fontSize: "0.95rem" }}>Loading your session...</p>
<style>{`
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
`}</style>
</div>
)
}
return user ? children : <Navigate to="/login" replace />
}