()
| 10 | import { Button } from "./components/ui/button"; |
| 11 | |
| 12 | function App() { |
| 13 | const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false); |
| 14 | const [isLoading, setIsLoading] = useState<boolean>(true); |
| 15 | |
| 16 | useEffect(() => { |
| 17 | // Check if user has a token in cookie |
| 18 | const token = document.cookie |
| 19 | .split("; ") |
| 20 | .find((row) => row.startsWith("session=")); |
| 21 | setIsAuthenticated(!!token); |
| 22 | setIsLoading(false); |
| 23 | }, []); |
| 24 | |
| 25 | // Protected route component |
| 26 | const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { |
| 27 | if (isLoading) { |
| 28 | return <div>Loading...</div>; |
| 29 | } |
| 30 | |
| 31 | if (!isAuthenticated) { |
| 32 | return <Navigate to="/login" replace />; |
| 33 | } |
| 34 | |
| 35 | return <>{children}</>; |
| 36 | }; |
| 37 | |
| 38 | return ( |
| 39 | <ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme"> |
| 40 | <div className="fixed top-2 right-2 z-50"> |
| 41 | <Button |
| 42 | variant="ghost" |
| 43 | size="icon" |
| 44 | onClick={() => { |
| 45 | window.open("https://github.com/BingyanStudio/github-analyzer", "_blank"); |
| 46 | }} |
| 47 | > |
| 48 | <GithubIcon className="h-5 w-5" /> |
| 49 | </Button> |
| 50 | <ThemeToggle /> |
| 51 | </div> |
| 52 | <BrowserRouter> |
| 53 | <Routes> |
| 54 | <Route |
| 55 | path="/login" |
| 56 | element={ |
| 57 | isAuthenticated ? <Navigate to="/dashboard" replace /> : <Login /> |
| 58 | } |
| 59 | /> |
| 60 | <Route |
| 61 | path="/callback" |
| 62 | element={<Callback setIsAuthenticated={setIsAuthenticated} />} |
| 63 | /> |
| 64 | <Route |
| 65 | path="/dashboard" |
| 66 | element={ |
| 67 | <ProtectedRoute> |
| 68 | <Dashboard /> |
| 69 | </ProtectedRoute> |
nothing calls this directly
no outgoing calls
no test coverage detected