Commit
·
fc6d4e4
1
Parent(s):
75706d4
Add ProtectedRoute component for route guarding based on authentication
Browse files
src/routes/protectedRoute.tsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from "react";
|
| 2 |
+
import { Navigate, Outlet } from "react-router-dom";
|
| 3 |
+
|
| 4 |
+
const ProtectedRoute: React.FC = () => {
|
| 5 |
+
const isAuthenticated = !!localStorage.getItem("auth_token");
|
| 6 |
+
|
| 7 |
+
return isAuthenticated ? <Outlet /> : <Navigate to="/signin" />;
|
| 8 |
+
};
|
| 9 |
+
|
| 10 |
+
export default ProtectedRoute;
|