UNPKG

nbd-app

Version:

🚀 CLI tool to scaffold full-stack authentication starter projects with React, Node.js, and multiple auth providers (Email, Google, and more)

23 lines (17 loc) • 546 B
import { Navigate } from "react-router-dom"; import { useAuth } from "../context/AuthContext"; const ProtectedRoute = ({ children }) => { const { isAuthenticated, loading } = useAuth(); if (loading) { return ( <div className="flex justify-center items-center h-64"> <div className="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-primary-500"></div> </div> ); } if (!isAuthenticated) { return <Navigate to="/login" replace />; } return children; }; export default ProtectedRoute;