aboutsummaryrefslogtreecommitdiff
path: root/web/src/components/auth
diff options
context:
space:
mode:
authorzwlucas <lucas.fariamo08@gmail.com>2026-07-25 21:23:29 +0000
committerzwlucas <lucas.fariamo08@gmail.com>2026-07-25 21:23:29 +0000
commitef55d9bb24430610b60c1b77821307cd72c08c55 (patch)
treee6935a810b34370b0a4c821e55f6397aac50c832 /web/src/components/auth
downloadhelpdesk-master.tar.gz
helpdesk-master.zip
feat: upload of the projectHEADmaster
Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
Diffstat (limited to 'web/src/components/auth')
-rw-r--r--web/src/components/auth/ProtectedRoute.tsx20
1 files changed, 20 insertions, 0 deletions
diff --git a/web/src/components/auth/ProtectedRoute.tsx b/web/src/components/auth/ProtectedRoute.tsx
new file mode 100644
index 0000000..1133d36
--- /dev/null
+++ b/web/src/components/auth/ProtectedRoute.tsx
@@ -0,0 +1,20 @@
+/**
+ * ProtectedRoute.tsx
+ * Redireciona para /login se o usuário não estiver autenticado.
+ */
+
+import { Navigate, useLocation } from 'react-router-dom';
+import { useAuth } from '@/context/AuthContext';
+import type { ReactNode } from 'react';
+
+export function ProtectedRoute({ children }: { children: ReactNode }) {
+ const { isAuthenticated } = useAuth();
+ const location = useLocation();
+
+ if (!isAuthenticated) {
+ // Preserva a rota que o usuário tentou acessar para redirect pós-login
+ return <Navigate to="/login" state={{ from: location }} replace />;
+ }
+
+ return <>{children}</>;
+}