Improve ProtectedRoute
This commit is contained in:
parent
ba1f48ad0d
commit
2e429535ab
2 changed files with 4 additions and 3 deletions
|
|
@ -26,7 +26,7 @@ export const App = () => {
|
|||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<ProtectedRoute to="/landing">
|
||||
<TabloPage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@ import { useSession } from "../contexts/SessionContext";
|
|||
import { Navigate } from "react-router-dom";
|
||||
interface ProtectedRouteProps {
|
||||
children: ReactNode;
|
||||
to?: string;
|
||||
}
|
||||
|
||||
export const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
|
||||
export const ProtectedRoute = ({ children, to }: ProtectedRouteProps) => {
|
||||
const { session } = useSession();
|
||||
if (!session) {
|
||||
return <Navigate to="/login" replace />;
|
||||
return <Navigate to={to ?? "/login"} replace />;
|
||||
}
|
||||
|
||||
// If authenticated, render the protected component
|
||||
|
|
|
|||
Loading…
Reference in a new issue