Protect React routes with GitHat authentication. Client-side route guards, loading states, and automatic redirects for unauthenticated users.
Use ProtectedRoute to guard dashboard pages, settings, and any authenticated content. It handles loading states and redirects automatically.
Define your React Router routes normally, then wrap private routes in ProtectedRoute. The redirect preserves the attempted URL so users return after sign-in.
ProtectedRoute accepts a fallback prop rendered during auth checking. Default is null (blank screen). Pass a loading component for better UX.
import { ProtectedRoute } from '@githat/nextjs';
// Protected route setup with React Router
import { ProtectedRoute } from '@githat/nextjs';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/sign-in" element={<SignIn />} />
<Route path="/sign-up" element={<SignUp />} />
<Route path="/dashboard" element={
<ProtectedRoute fallback={<p>Loading...</p>}>
<Dashboard />
</ProtectedRoute>
} />
</Routes>
</BrowserRouter>
);
}
Try GitHat free
Ship authenticated apps in minutes, not weeks.