mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-19 05:09:54 +02:00
[dyad] wrote 6 file(s)
This commit is contained in:
1 parent
52267eb3ca
commit
1ce71f37c2
6 files changed
+751
-150
No files matched your search
+8
-19
@@ -8,13 +8,14 @@ import { useEffect, useState } from "react";
|
||||
import Index from "./pages/Index";
|
||||
import Login from "./pages/Login";
|
||||
import NotFound from "./pages/NotFound";
|
||||
import AuthService from "./services/AuthService";
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
// Protected Route Component
|
||||
const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
|
||||
const token = localStorage.getItem("token");
|
||||
if (!token) {
|
||||
const isAuthenticated = AuthService.isAuthenticated();
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/login" replace />;
|
||||
}
|
||||
return <>{children}</>;
|
||||
@@ -25,24 +26,12 @@ const App = () => {
|
||||
|
||||
useEffect(() => {
|
||||
// Vérifier le token au démarrage
|
||||
const token = localStorage.getItem("token");
|
||||
if (token) {
|
||||
// Optionnel: Vérifier la validité du token avec le serveur
|
||||
fetch("/api/auth/me", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.catch(() => {
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("user");
|
||||
})
|
||||
.finally(() => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
} else {
|
||||
const checkAuth = async () => {
|
||||
const isValid = await AuthService.checkTokenValidity();
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
checkAuth();
|
||||
}, []);
|
||||
|
||||
if (isLoading) {
|
||||
|
||||
Reference in new issue
Block a user